你可以告訴的過程中不使用窗口或將其最小化:
// don't execute on shell
p.StartInfo.UseShellExecute = false;
p.StartInfo.CreateNoWindow = true;
// don't show window
p.StartInfo.WindowStyle = ProcessWindowStyle.Minimized;
與UseShellExecute = false
您可以重定向輸出:
// redirect standard output as well as errors
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
當你這樣做,你的肩膀D使用輸出緩衝器的非同步讀出,以避免死鎖由於過度填充緩衝器:
StringBuilder outputString = new StringBuilder();
StringBuilder errorString = new StringBuilder();
p.OutputDataReceived += (sender, e) =>
{
if (e.Data != null)
{
outputString.AppendLine("Info " + e.Data);
}
};
p.ErrorDataReceived += (sender, e) =>
{
if (e.Data != null)
{
errorString.AppendLine("EEEE " + e.Data);
}
};
UseShellExecute = false還將允許您將STDOUT和STDERR重定向到可能有用的流。 –
@SrikanthVenugopalan因爲OP已經做到了,所以我把它放了出來。 – Matten
是的,你是對的,我的不好。雖然,我個人覺得RedirectStandardError更重要。 –