I have an executable, which runs fine when i run it manually, and it exists as it should with the expected output. But when i run it with the method bellow, the Process.Exited event is never fired. Notice that i have remembered the Process.EnableRaisingEvents
protected override Result Execute(RunExecutable task)
{
var process = new Process();
process.StartInfo.Arguments = task.Arguments;
process.StartInfo.FileName = task.ExecutablePath;
process.StartInfo.CreateNoWindow = true;
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardOutput = true;
process.EnableRaisingEvents = true;
process.Exited += (sender, args) =>
{
processSync.OnNext(new Result
{
Success = process.ExitCode == 0,
Message = process.StandardOutput.ReadToEnd()
});
processSync.OnCompleted();
};
process.Start();
return processSync.First();;
}
The problem is the same, if i use Process.WaitForExit() instead of reactive extensions, to wait for the exit event.
Also, if i run the process with another argument, which produces another output, it exists fine.
It seems to have something to do with the process.StartInfo.RedirectStandardOutput = true;
since when i disable this, it works. But that could just be a symptom of another problem.
Any help is appreciated :-)
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…