I have a service that needs to start processes and wait for them to exit, and I use something like:
process.Start(); int timeout = ... // some normal value in milliseconds process.WaitForExit(timeout); try { //ExitCode throws if the process is hanging return (CommandErrorCode)process.ExitCode; } catch (InvalidOperationException ioex) { return CommandErrorCode.InternalError; }
where CommandErrorCode is something like
public enum CommandErrorCode { Success = 0,
Btw, I redirect both standard output and standard error and use the BeginXXXReadLine and XXXDataReceived handlers and I have no problems, but the processes I use are known, well defined and well behaved.
Sweko
source share