Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

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/". Heres the thing. When prints out total content equal to or less than 488 characters, everything works properly. But if 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? is literally: print "x" x 488 when it works and print "x" x 489 when it doesn't.

Replies are listed 'Best First'.
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...


      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?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://415037]
Approved by zejames
Front-paged by Courage
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (3)
As of 2018-06-22 23:55 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (124 votes). Check out past polls.