c# execute shell command and get result

29,299

try this

string output = proc.StandardOutput.ReadToEnd();
Share:
29,299
Mika
Author by

Mika

Updated on April 30, 2021

Comments

  • Mika
    Mika about 3 years

    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?