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,302
  • 4
  • 28
  • 33
Mika
  • 1,125
  • 5
  • 20
  • 34

1 Answers1

20

try this

string output = proc.StandardOutput.ReadToEnd();
Sachin
  • 39,043
  • 7
  • 86
  • 102