15

I am executing a command prompt command as follows:

string cmd = "/c dir" ; 
System.Diagnostics.Process proc = new System.Diagnostics.Process(); 
proc.StartInfo.FileName = "cmd.exe";
proc.StartInfo.Arguments = cmd; 
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.RedirectStandardOutput = true; 
proc.Start();

How to I get the output of the command?

Cleptus
  • 3,446
  • 4
  • 28
  • 34
Mika
  • 1,195
  • 6
  • 22
  • 34

1 Answers1

20

try this

string output = proc.StandardOutput.ReadToEnd();
Sachin
  • 40,216
  • 7
  • 90
  • 102