-1
Hellp。在我的'管道'中,我有3个应该按顺序执行的命令,并且每个请求都必须等到上一个命令结束。现在我已经完成了第一个请求,但第二个和第三个只是跳过... 你能否建议如何改变这个'管道'?在cmd中执行几个命令。执行只有一个命令
string strCmdText = s1;
var startInfo = new ProcessStartInfo
{
FileName = "cmd.exe",
RedirectStandardInput = true,
RedirectStandardOutput = true,
UseShellExecute = false,
CreateNoWindow = true
};
var process = new Process { StartInfo = startInfo };
process.Start();
process.StandardInput.WriteLine(strCmdText);
process.WaitForExit();
string strCmdText1 = s2;
process.StandardInput.WriteLine(strCmdText1);
process.WaitForExit();
string strCmdText2 = s3;
process.StandardInput.WriteLine(strCmdText2);
process.StandardInput.WriteLine("exit");
谢谢。
首先,你为什么要通过CMD,第二,*究竟是什么*“不起作用”? – 2014-12-05 23:46:52
刚刚检查了你的代码,一切都像魅力一样。 – 2014-12-05 23:56:37
当我编写有意义的代码时,它工作正常。请注意,在您的示例中,在继续编写新命令之前,您需要调用WaitForExit()。当我尝试这样做时,我从未接触过下一个命令;它仍然停留在对'WaitForExit()'的调用中。如果您需要帮助,请提供一个很好的代码示例,并具体说明您正在尝试做什么,发生了什么,以及如何与您想要的不同。请参阅http://stackoverflow.com/help/mcve和http://stackoverflow.com/help/how-to-ask – 2014-12-06 00:07:33