Hi monks,
I'm having troubles deciphering exactly what is going on in some fork open pipe code, despite reading
perlopentut and
perlipc slowly and repeatedly. I have stripped out as much as I can and added some comment-questions:
open(P, "|-") or # fork a process using fh
# P as STDIN to the child.
do { # huh? Why would open P fail...
# and we launch child?!?
open(STDERR,">&=$err"); # alias STDERR to output
# to the $err filehandle
open(STDOUT,">&=$out"); # alias STDOUT to output
# to the $out filehandle
exec(@cmd); # run command. How to
# capture @cmd errors gracefully?
exit 9 # what is 9's special
# meaning here?
};
close($err);
close($out);
print P "test input to child" or die ("Mein Leiben! $!");
close(P) or die("Stella! $!");
Admittedly, I'm most puzzled by the "open or do". I find that a very strange way to fork open a child process. Since this subroutine is called many times, how might the open fail and prompt the opening of the child? I would expect the open to be mandatory - AND - the do to be mandatory. Urg.
Thank you very much for your time and help.
Thanks!
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.