我想使用以下代码从C#运行命令,但应用程序无限期地等待:
System.Diagnostics.Process p = new System.Diagnostics.Process();
p.StartInfo.UseShellExecute = false;
p.StartInfo.CreateNoWindow = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.Arguments = command;
p.Start();
p.WaitForExit();
p.StandardOutput.ReadToEnd();
我做了调试,最后一个断点是p.WaitForExit()
。我究竟做错了什么?
顺便说一句,我尝试手动运行命令,我得到的结果是毫秒。
答案 0 :(得分:0)
尝试将a / C添加到您的参数中 - 没有它,cmd.exe终止