Link to home
Start Free TrialLog in
Avatar of baburkhan
baburkhan

asked on

detecting the ouput from the command prompt?

i want to make form so that when i enter values in that form (obviously textbox or other) that go and write on the command prompt like i write 'dir' in the textbox it should write dir in the command prompt and when the command prompt gives the output , the output values should appear in the form fields in some list or something, e.g. if i write 'dir' in the text box it shows all the directories in the drive in the list box on the form, further can i arrange the ouput values in the list box as i want? i will be thankful if you people give me some coding or technique how can i handle this. thanks so much ,  i will be waiting for the answers.
Avatar of gregoryyoung
gregoryyoung
Flag of Canada image

use the process object to start it (System.Diagnostics.Process)

There are Streams available for
StandardInput
StandardOutput
StandardError

Process p = new Process();
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.FileName = "test.exe";
p.Start();
p.WaitForExit();
string output = p.StandardOutput.ReadToEnd();


However doing this with Dir is a bad idea as you can use the directory objects and file objects to get all of this information without having to go through all of the trouble to parse the output etc. Take a look at ... System.IO.Directory




use the process object to start it (System.Diagnostics.Process)

There are Streams available for
StandardInput
StandardOutput
StandardError

Process p = new Process();
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.FileName = "test.exe";
p.Start();
p.WaitForExit();
string output = p.StandardOutput.ReadToEnd();


However doing this with Dir is a bad idea as you can use the directory objects and file objects to get all of this information without having to go through all of the trouble to parse the output etc. Take a look at ... System.IO.Directory




Avatar of baburkhan
baburkhan

ASKER

thanks , well what if i do use the 'shell' i can use the system dot come and dot exe exentention like ping but i want them to print the output result at my form not in the console.
ASKER CERTIFIED SOLUTION
Avatar of gregoryyoung
gregoryyoung
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
oops got ping nfo not got directory :)