in ILRepack.IntegrationTests/Helpers/ObservableProcess.cs [22:70]
public ObservableProcess(ProcessStartInfo startInfo, bool throwOnNonZeroExitCode = true)
{
startInfo.RedirectStandardError = startInfo.RedirectStandardOutput = startInfo.RedirectStandardInput = true;
process = new Process { StartInfo = startInfo, EnableRaisingEvents = true };
process.OutputDataReceived += OnReceived;
process.ErrorDataReceived += OnReceived;
process.Start();
process.BeginOutputReadLine();
process.BeginErrorReadLine();
input = Observer.Create<string>(
x => { process.StandardInput.WriteLine(x); process.StandardInput.Flush(); },
() => { });
Observable.Start(() =>
{
int exitCode;
try
{
process.WaitForExit(60 * 1000);
}
finally
{
// recreate flush logic from System.Diagnostics.Process
WaitUntilEndOfFile("output");
WaitUntilEndOfFile("error");
exitCode = process.ExitCode;
process.OutputDataReceived -= OnReceived;
process.ErrorDataReceived -= OnReceived;
process.Close();
}
output.OnCompleted();
if (exitCode != 0 && throwOnNonZeroExitCode)
{
var error = string.Join("\n", output.ToArray().First());
exit.OnError(new Exception(error));
}
else
{
exit.OnNext(exitCode);
exit.OnCompleted();
}
}, Scheduler.Default);
}