I have an executable that works fine when I run it manually, and it exists as expected with the expected output. But when I fire it using the method below, the Process.Exited event never fires. Note that I remember 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 started the process with a different argument that produces a different output, it exists normally.
Something seems to be related to process.StartInfo.RedirectStandardOutput = true; because when i turn it off it works. But this may just be a symptom of another problem.
Any help is appreciated :-)
c # events process
Lars Udengaard
source share