in reply to Re^4: How can I read DATA in parent and child?
in thread How can I read DATA in parent and child?
It works sometimes.
As I do an fdopen, I think it should work each time. Infact: I'm just running below code and it's giving me the expected result now the 20th time.
Here is the (slightly modified) code, which I think should work.
use IO::Handle; use strict; use warnings; my $pos= tell *DATA; my $pid= fork(); die unless defined $pid; if ($pid == 0) { my $x= IO::Handle->new(); $x->fdopen(fileno(DATA), "r"); seek $x, $pos, 0; print "Start c\n"; sleep 4; while (<$x>) { print "c: $_"; sleep 1; } print "stop c\n"; } else { my $y= IO::Handle->new(); $y->fdopen(fileno(DATA), "r"); seek $y, $pos, 0; print "Start p\n"; while (<$y>) { print "p: $_"; sleep 1; } print "waiting for child\n"; wait; print "stop p\n"; } __DATA__ a b c d e
s$$([},&%#}/&/]+}%&{})*;#$&&s&&$^X.($'^"%]=\&(|?*{%
+.+=%;.#_}\&"^"-+%*).}%:##%}={~=~:.")&e&&s""`$''`"e
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^6: How can I read DATA in parent and child?
by choroba (Cardinal) on Feb 19, 2019 at 09:38 UTC | |
by Skeeve (Parson) on Feb 19, 2019 at 10:25 UTC | |
by tybalt89 (Monsignor) on Feb 19, 2019 at 16:41 UTC | |
by Skeeve (Parson) on Feb 20, 2019 at 07:06 UTC | |
by tybalt89 (Monsignor) on Feb 20, 2019 at 10:06 UTC | |
by hippo (Bishop) on Feb 20, 2019 at 09:09 UTC | |
by Skeeve (Parson) on Feb 19, 2019 at 10:46 UTC | |
by tybalt89 (Monsignor) on Feb 20, 2019 at 10:33 UTC |
In Section
Seekers of Perl Wisdom