in reply to Re: win32 open3 strangeness
in thread win32 open3 strangeness

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        

  • Comment on Re^2: win32 open3 strangeness (classic race, no fork)

Replies are listed 'Best First'.
Re^3: win32 open3 strangeness (classic race, no fork)
by BUU (Prior) on Dec 15, 2004 at 23:22 UTC
    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?

      I don't believe it is. If you think it is, then present some evidence.

      Come to think of it, I'd be surprised if this were the problem at 488 characters. 512 I could believe. But perhaps it is printing out some other stuff?

      With the few precise details provided, it is a big guessing game.

      - tye        

        The exact code looks like:
        my( $write, $read, $error, $pid ); if( $is_win32 ) { print "here2\n"; open my $file, "<", $_ or warn "Can't open $_ for read +ing"; #log chomp( my $shebang = <$file> ); close $file; warn "Bad shebang: $shebang - $_" unless $shebang =~ s +/^\#!//; #log #shitty highlighting #warn "$shebang $_"; #log print "here 3\n"; print "$shebang $_",$/; eval{ $pid = open3( $write, $read, $error, $shebang, $ +_ ) }; print "here 4\n"; }
        I have buffering turned off and when I run that snippet I get:
        here2 here 3 perl usr/test.pl
        Where "perl usr/test.pl" is the $shebang $_ line. usr/test.pl looks like:
        #!perl print "x" x 489;
        If I change the 489 to 488, everything works perfectly. However, this is run from a forked subprocess, which is apparently causing the error, as when I run that open3 line from the command line via perl -e, it works perfectly, so theres something screwy with multiple forks.

        For example, this command line invocation seems to (randomly?) hang D:\home\buu\pas>perl -le"use IPC::Open3 qw/open3/; fork; fork; print $$; open3($w, $r, $e, 'perl', 'usr/test.pl'); print <$r>" With test.pl being the same as I quoted above.