in reply to Re^2: ActiveState woes : Is it EOF-blind?
in thread ActiveState woes : Is it EOF-blind?
By has no effect what do you mean? With the reader loop as written, on Win32, without the 0x1a it gets both lines, then hangs (blocks), awiating EOF. With the 0x1a it detects the end of the input and then finishes. Tested on Win2k SP2, AS perl 5.6.1
To get it to run as written on Linux (CentOS) perl 5.10 you need to close $wtr. Sending 0x1a makes no difference.
[james@adajio ~]$ cat cat.pl $|++; print while <>; [james@adajio ~]$ cat ipc.pl #!/usr/bin/perl use strict; use IPC::Open2; $|++; my $EOF = ''; # chr(0x1a); # inline use "\x1a" my $perl = "/usr/bin/perl"; my $cat = "/home/james/cat.pl"; my $data = "first line\nsecond line"; my $pid = open2(my $rdr, my $wtr, $perl, $cat ); print "Sending:\n$data\n----\n"; print $wtr $data .$EOF; close $wtr; print "Going for read!\n"; print while <$rdr>; [james@adajio ~]$ ./ipc.pl Sending: first line second line ---- Going for read! first line second line [james@adajio ~]$
So on linux the act of closing $wtr effectively sends the EOF signal. Physically sending apparently does nothing. Sending a \n at the end of the $data string allows reading of the second line but it still hangs awaiting EOF. Thus a portable way of doing it is to send the EOF (makes it work on Win32) and close $wtr (makes it work on *nix) - as this ensures perl gets a detectable EOF into the $rdr stream.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: ActiveState woes : Is it EOF-blind?
by ikegami (Patriarch) on May 06, 2008 at 04:45 UTC | |
by BrowserUk (Patriarch) on May 06, 2008 at 10:12 UTC | |
by ikegami (Patriarch) on May 06, 2008 at 12:26 UTC |