Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

win32 open3 strangeness

by BUU (Prior)
on Dec 15, 2004 at 14:49 UTC ( #415037=perlquestion: print w/ replies, xml ) Need Help??
BUU has asked for the wisdom of the Perl Monks concerning the following question:

I have a perl script which does some stuff. One of the things it does is fork a child and wait for results from the child. The child executes this simple piece of code:
eval{ $pid = open3( $write, $read, $error, $shebang, $_ ) };
Where $write, $read, $error are all empty to be used as filehandles, $shebang is "perl" and $_ is "usr/test.pl". Heres the thing. When test.pl prints out total content equal to or less than 488 characters, everything works properly. But if test.pl prints out 488 characters, the open3 call hangs and the script never advances beyond it. Anyone have the vaguest idea where I could look, or what I could use instead of open3?

Test.pl is literally: print "x" x 488 when it works and print "x" x 489 when it doesn't.

Comment on win32 open3 strangeness
Select or Download Code
Re: win32 open3 strangeness
by demerphq (Chancellor) on Dec 15, 2004 at 15:07 UTC

    Are you on the latest relevent perl build? I had weird problems with forking that were resolved by an upgrade. I cant help but wonder if maybe these are related...

    ---
    demerphq

      IPC::Open3 doesn't use fork on Win32.

      This is the classic race condition inherent in using open3. The subprocess is blocking waiting for the output to be read and so isn't reading while the parent is blocked writing to the subprocess waiting for the subprocess to read. Or the subprocess is blocking reading while the parent is blocking reading output that the subprocess has buffered and so isn't available for reading yet. And there is no good way to get around this because you can't tell if you are going to end up in the first deadlock case or the second.

      Using select could help except select doesn't work on non-sockets in Win32. You could use a Win32::SelectablePipe instead of pipe except that I don't think the (broken) snippet from tye's scratchpad has been turned into a CPAN module yet by my minions. ;)

      - tye        

        Er, what you say makes a certain amount of sense, but why is it blocking at the actual open3() call? Why wouldn't it block when I try to read or write?

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://415037]
Approved by zejames
Front-paged by Courage
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (13)
As of 2014-07-25 17:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (174 votes), past polls