c#执行shell命令并获取结果

时间:2013-04-04 20:23:41

标签: c# shell command output prompt

我正在执行命令提示符命令,如下所示:

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();

如何获取命令的输出?

1 个答案:

答案 0 :(得分:19)

试试这个

string output = proc.StandardOutput.ReadToEnd();