vsespb has asked for the wisdom of the Perl Monks concerning the following question:
subcommand1.pl:use strict; use warnings; use IO::Handle; $^F = 100; pipe READHANDLE,WRITEHANDLE; binmode READHANDLE; binmode WRITEHANDLE; WRITEHANDLE->autoflush; READHANDLE->autoflush; unless (fork()){ exec $^X, $ARGV[0], fileno(READHANDLE); die; } print WRITEHANDLE "Test!\n"; close WRITEHANDLE; wait;
subcommand2.pl:open IN, "<&", $ARGV[0] or die $!; binmode IN; while(defined($_ = <IN>)) { print "line $_"; } close IN;
Problem:open IN, "<&", $ARGV[0] or die $!; binmode IN; my $s = <IN>; print "line: $s"; close IN;
hangs after first line, whileperl main.pl subcommand1.pl
works fine.perl main.pl subcommand2.pl
cat subcommand1.pl | perl subcommand1.pl 0
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: File handle passing issue under *nix
by McA (Priest) on Sep 30, 2013 at 19:16 UTC | |
by vsespb (Chaplain) on Sep 30, 2013 at 19:32 UTC | |
by McA (Priest) on Sep 30, 2013 at 19:48 UTC |