Send input to CMD from WINFORM
-
Hi. I have a winform that creates a process(cmd) and redirects its inputstream and outputstream to streamwriter and streamreader. im able to write a command to that process(dir for example) and get the output and display it on textbox. however, it seems that after i write to the inputstream i have to close it , only if i close the stream the command that ive sended is executed. i want to be able to write more command to that stream and keep it open. using the "flush" method on the streamwriter dosent seems to work. how can i accomplish that task?
-
Hi. I have a winform that creates a process(cmd) and redirects its inputstream and outputstream to streamwriter and streamreader. im able to write a command to that process(dir for example) and get the output and display it on textbox. however, it seems that after i write to the inputstream i have to close it , only if i close the stream the command that ive sended is executed. i want to be able to write more command to that stream and keep it open. using the "flush" method on the streamwriter dosent seems to work. how can i accomplish that task?
Does your command end with CR+LF? It's just a guess but I think you need to send the equivalent of pressing Enter at a command prompt (i.e. in Cmd window).
Regards David R --------------------------------------------------------------- "Every program eventually becomes rococo, and then rubble." - Alan Perlis
-
Hi. I have a winform that creates a process(cmd) and redirects its inputstream and outputstream to streamwriter and streamreader. im able to write a command to that process(dir for example) and get the output and display it on textbox. however, it seems that after i write to the inputstream i have to close it , only if i close the stream the command that ive sended is executed. i want to be able to write more command to that stream and keep it open. using the "flush" method on the streamwriter dosent seems to work. how can i accomplish that task?
Your app has a lot of problems with the console because console window doesn't belong to the caller process.If you want be able to read or write to console from Win forms in the same way like console application you should call AllocConsole or AttachConsole native functions to create or assign console window that belong to your windows forms app,not just to external process.To close current process console window you should call FreeConsole function.See some sample code here.
Life is a stage and we are all actors!