[prog] Process execution in Perl

Wolfgang Petzold petzold at villa-chaos.de
Thu Sep 18 15:51:52 EST 2003


Dan Richter, 18.09.03:

> I'm trying to create a sort of pipe in Perl doing this:
>
>    open PIPE, "| cat |" or die;
>
> When I run the program without warnings, everything works fine. When I run
> the program with warnings, it displays a warning message saying "Can't open
> bidirectional pipe at ...", but the program still succeeds (I can read from
> and write to the pipe).

I'm not quite sure about this, but does it *really* succeed? I just tried

--bidirpipe.pl---------------------------------------------------------------
open PIPE, "| cat |";

for (1 .. 4) { print PIPE "line $_\n"; }
while (<PIPE>) { print "output from perl script: ", $_; }

print STDERR "exiting now.\n";
exit(0);
-----------------------------------------------------------------------------

and got

-----------------------------------------------------------------------------
stubb$ perl bidirpipe.pl
exiting now.
stubb$ line 1
line 2
line 3
line 4
-----------------------------------------------------------------------------

which isn't what I would have expected if the open call were working
properly.

"perldoc perlopentut" suggests to use IPC::Open2 for opening bidirectional
pipes and refers also to "perldoc perlipc".

Cheers
Wolfgang



More information about the Programming mailing list