in Common/Product/SharedProject/ProcessOutput.cs [263:345]
private ProcessOutput(Process process, Redirector redirector)
{
this.arguments = QuoteSingleArgument(process.StartInfo.FileName) + " " + process.StartInfo.Arguments;
this.redirector = redirector;
if (this.redirector == null)
{
this.output = new List<string>();
this.error = new List<string>();
}
this.Process = process;
if (this.Process.StartInfo.RedirectStandardOutput)
{
this.Process.OutputDataReceived += this.OnOutputDataReceived;
}
if (this.Process.StartInfo.RedirectStandardError)
{
this.Process.ErrorDataReceived += this.OnErrorDataReceived;
}
if (!this.Process.StartInfo.RedirectStandardOutput && !this.Process.StartInfo.RedirectStandardError)
{
// If we are receiving output events, we signal that the process
// has exited when one of them receives null. Otherwise, we have
// to listen for the Exited event.
// If we just listen for the Exited event, we may receive it
// before all the output has arrived.
this.Process.Exited += this.OnExited;
}
this.Process.EnableRaisingEvents = true;
try
{
this.Process.Start();
}
catch (Exception ex)
{
if (IsCriticalException(ex))
{
throw;
}
if (this.redirector != null)
{
foreach (var line in SplitLines(ex.ToString()))
{
this.redirector.WriteErrorLine(line);
}
}
else if (this.error != null)
{
this.error.AddRange(SplitLines(ex.ToString()));
}
this.Process = null;
}
if (this.Process != null)
{
if (this.Process.StartInfo.RedirectStandardOutput)
{
this.Process.BeginOutputReadLine();
}
if (this.Process.StartInfo.RedirectStandardError)
{
this.Process.BeginErrorReadLine();
}
if (this.Process.StartInfo.RedirectStandardInput)
{
// Close standard input so that we don't get stuck trying to read input from the user.
if (this.redirector == null || (this.redirector != null && this.redirector.CloseStandardInput()))
{
try
{
this.Process.StandardInput.Close();
}
catch (InvalidOperationException)
{
// StandardInput not available
}
}
}
}
}