這是一個有點複雜的問題。我嘗試過所有可能的事情,但仍然沒有工作。我運行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'作爲您的問題記錄添加到命令的末尾?也許相關 - 是否有任何理由重定向輸入? –