in reply to Re: ActiveState woes : Is it EOF-blind?
in thread ActiveState woes : Is it EOF-blind?

Thank you to all your suggestions. So I tried to modify my example program in two ways: This results in the following programs:
# This is cat.pl $|=1; while(<>) { print; } chr(0x1a) if $^O eq 'MSWin32';
and
# This is ls.pl use strict; use warnings; use IPC::Open2; # OUTPUT: Filehandle for output from cat.pl # INPUT: Filehandle for input to cat.pl open2(*OUTPUT,*INPUT,"$^X", "cat.pl") or die "$!"; print INPUT "first line\nsecond line\n"; if ($^O eq 'MSWin32') { select INPUT; $| = 1; print INPUT chr(0x1a); } close INPUT; my @result=<OUTPUT>; close OUTPUT; print "RESULT:\n@result\n";
Still, using the programs on Windows like this:
perl ls.pl
causes it to hang.
-- 
Ronald Fischer <ynnor@mm.st>

Replies are listed 'Best First'.
Re^3: ActiveState woes : Is it EOF-blind?
by ikegami (Patriarch) on May 06, 2008 at 12:09 UTC

    You seem to have incorporated all the comments except the ones that mattered.

    • $|=1 for STDOUT in cat.pl is technically not needed in this case because you expect the child to end before you start reading. It's good to have, though.

    • $|=1 for INPUT in ls.pl is already done by open2. And if it wasn't, it would need to be done in unix too.

    • Your problem is caused by a bug in IPC::Open3 and by proxy in IPC::Open2.

    • The chr(0x1a) shouldn't be needed, but it's a workaround for the bug. However, it doesn't work with PerlIO (which is used by ActiveState since 5.8 and probably used by the default on all Perls since 5.8).

    By the way, the die "$!" in open2(*OUTPUT,*INPUT,"$^X", "cat.pl") or die "$!"; will never get executed since open2 throws an exception on error. Good thing, cause $! is only appropriate for systems calls and this isn't one.

      Point taken! :-/
      Thank your for your helpful explanation!
      -- 
      Ronald Fischer <ynnor@mm.st>