Syntactic Confectionery Delight | |
PerlMonks |
Problems forking and redirecting STDOUT with Win32by xdg (Monsignor) |
on Dec 07, 2005 at 16:11 UTC ( [id://514879]=perlquestion: print w/replies, xml ) | Need Help?? |
xdg has asked for the wisdom of the Perl Monks concerning the following question: I've been trying to debug some test failures on IPC::Run3 on Win32. One of the tests evaluates how IPC::Run3 performs when called from a child process (which, of course, is really a thread on Win32). I'm seeing some very unusual results in how file descriptors get duplicated from within a child process. On investigation, I think it may be related to this perlbug. which has been sitting idle for a long time. As an illustration of the issue, I took an example from the end of that bug report:
When I run this under Linux, "child" is written to test.txt and "parent" is printed to the console. However, when run under Win32 (Activestate 5.8.7 Build 815), both "child" and "parent" are written to test.txt and nothing is printed to the console. Out of curiousity, I tried closing STDOUT before re-opening it, like this:
Again, on Linux, "parent" goes to the console and "child" to test.txt. On Win32, though, the behavior reverses. "child" and "parent" are printed to the console and nothing is written to test.txt. (Side note: test.txt is still truncated). I'm interested in any suggestions or alternatives for how to make this work consistently and portably. Thanks! Update: To clarify the solution I'm seeking -- it's not an alternative for the fork. I'm aware that there are probably better alternatives on Win32. The question is (I think): given that a fork has been done, is there a way of redirectly STDOUT safely in a way that doesn't also affect the parent so that system gets the right filehandle? If this can't be done, then IPC::Run3 will probably just need to skip the fork tests on Win32. -xdg Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.
Back to
Seekers of Perl Wisdom
|
|