简体   繁体   English

从C#运行命令外壳

[英]Running a command shell from C#

I want to run a command from C# with below code but the application waits infinitely: 我想使用以下代码从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();

I did a debug and the last break point passed is p.WaitForExit() . 我进行了调试,最后通过的断点是p.WaitForExit() What am I doing wrong? 我究竟做错了什么? By the way, I tried run the command manually and I get the result in miliseconds. 顺便说一句,我尝试手动运行命令,结果以毫秒为单位。

尝试在参数前面加上一个/ C-没有它,cmd.exe将不会终止

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM