这是一个有点复杂的问题。我尝试过所有可能的事情,但仍然没有工作。我运行CMD运行WinForm应用程序,然后在cmd上运行另一个应用程序(控制台应用程序)。它在/c START xyz
上工作,但是当应用程序结束时CMD总是关闭。我想暂停这个窗口。如何在执行后保持控制台窗口打开?
ProcessStartInfo processInfo = new ProcessStartInfo {
FileName = "cmd.exe",
WorkingDirectory = Path.GetDirectoryName(YourApplicationPath),
Arguments = "/K START " + cmdparametr,
RedirectStandardOutput = true,
RedirectStandardInput = true,
RedirectStandardError = true,
CreateNoWindow = false,
UseShellExecute = false,
WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal,
};
Process p = new Process {
StartInfo = processInfo
};
p.Start();
int ExitCode;
p.WaitForExit();
// *** Read the streams ***
string output = p.StandardOutput.ReadToEnd();
string error = p.StandardError.ReadToEnd();
ExitCode = p.ExitCode;
MessageBox.Show("output>>" + (String.IsNullOrEmpty(output) ? "(none)" : output));
MessageBox.Show("error>>" + (String.IsNullOrEmpty(error) ? "(none)" : error));
MessageBox.Show("ExitCode: " + ExitCode.ToString(), "ExecuteCommand");
p.Close();
ReadStream
工作当我添加参数:START /b
但我认为这并不重要。
WaitForExit()
不起作用。
是否有可能通过命令暂停应用可能是这样的: /k start xyz.exe & PAUSE
?
我的应用程序是控制台应用程序!
您是否尝试过将'&pause'作为您的问题记录添加到命令的末尾?也许相关 - 是否有任何理由重定向输入? –