Given that the child process is expecting to read something
on stdin, you should start it with "open()" rather than with
"system()" -- this gives the parent process the ability to
continue opertation after the child is opened/started,
print data to the child process if/when needed, and also
provides the parent with the child's process-id, if you
want that, though you could probably just "close" it -- e.g.
my $child_pid = open( CHILD, "| child_program arg1 arg2" )
|| die "unable to start child_program\n";
# Feed the child, if that's necessary
select CHILD;
$|++; # turn off output buffering
print CHILD $/; # send a blank line
# give the child about 5 seconds to produce something
my $counter = 0;
until ( -s "child_output.file" or ++$counter == 5 ) {
sleep 1;
}
# now, we could kill $child_pid, or just:
close CHILD;
Depending on what the child is actually supposed to be doing,
there may be some traps here. Definitely read "perldoc -f
open" and "perldoc perlipc".
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.