C#执行Shell命令并获取结果

15

我正在执行以下命令提示符命令:

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个回答

20

试试这个

string output = proc.StandardOutput.ReadToEnd();

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接