Click here to Skip to main content
15,887,676 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

In case of crash or what-not I want to be able to release the outputs from a process I and monitoring strOut and stdErr on. I get the feeling that uncoupling the listeners and then setting
_process.StartInfo.RedirectStandardError = false; isn't going to work.


Is it possible to stop redirecting the process outputs or do I have to redirect them elsewhere?

Thanks in advance ^_^
Posted
Comments
Sergey Alexandrovich Kryukov 11-Jun-13 12:33pm    
"Crash" should mean process termination, right? In this case, everything locked by the process is anyway released. Or do you mean something else? Then please explain...
—SA
Andy Lanng 12-Jun-13 4:04am    
I think that the issue is that the sub-process doesn't have anywhere to direct it's outputs once I have told it to redirect. It appears that 'releasing' the output streams doesn't actually mean that they are directed elsewhere and so they fill up and the process freezes. I'll test it out and post my results :D
Sergey Alexandrovich Kryukov 12-Jun-13 12:52pm    
There is no such thing as sub-project, there is a child project, and it is no different form a completely independent process, with one trivial exclusion: your parent process "knows" exactly which process handle is the child's, as it is obtained from the first hand. This way, you can always, wait for child termination, kill it, get some information, etc. Also, you can set up re-direction of StandardOutput and StandardError the way you want, before starting the child. Do you know how to do it? and of course you need to make ProcessStartInfo.RedirectStandardError = false; (NOT _process.StartInfo)...
—SA
Andy Lanng 13-Jun-13 4:46am    
Thanks for the comments. Yes I am reading the outputs async with BeginReadOutput(), having already set the event listener. I found CancelReadOutput() which was exactly what I was looking for (doh!).
I still don't understand why my child process froze when the parent did not. I think there is something fundamental with IIS processes (w3wp which is the parent) that meant that the child process (robocopy) became orphaned but still had its std's pointing at a process that was no longer reading them.
So far, I have included a dtor in the object that calls the child that will try to call CancelReadxxx(), but I may also ask it to kill the process.
Sergey Alexandrovich Kryukov 13-Jun-13 12:04pm    
IIS process? Why? I makes me suspect that you might abuse something. Why using robocopy at all. Generally, starting a child process is a questionable practice, if not bad.
Now, processes are fully independent. If the child process goes wrong (it could hang without crashing and being terminated), it cannot directly affect another process, whatsoever (unless, say, the parent process uses some data from the chile process to screw up itself. What's to valuable in that process which you could not do in yours? Aren't you just wasting your time for uncertainties?
—SA

This depends entirely on how you launched the process. Did you launch the .EXE directly or did you supply the .EXE as a command line argument and you launched it by launched CMD.EXE instead??

But, once the process crashes, the process is dead and so are the standard streams. There's nothing left to redirect, so the question is pointless.
 
Share this answer
 
v2
Comments
Ron Beyer 11-Jun-13 20:58pm    
I think what he means if he uses Process.Start, redirects the outputs of the external process to his process, then HIS process crashes.
Dave Kreskowiak 12-Jun-13 1:00am    
Ah. I see, now that I've re-read the post.

Interesting. I can see why it would and wouldn't work at the same time. The only way to know for sure is to test it and see what happens.
Andy Lanng 12-Jun-13 4:02am    
Ron was correct in his interpretation. I will test and post if I find a solution
Thanks ^_^
DOH >_<<br mode="hold" />
Async start listening to channels:
C#
_windowsProcess.BeginOutputReadLine();
_windowsProcess.BeginErrorReadLine();


and to stop:
C#
_windowsProcess.CancelOutputRead();
_windowsProcess.CancelErrorRead();


I was looking for stop or end. This took me a while to find (guess I'm still no good at googling)

There are actually deeper issues but I already have a separate thread for that ( stdout and stderr Listener issues (causing frozen processes?)[^] )

Hopefully someone else will find this useful

Thanks all ^_^
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900