Ack! Why does everybody result to shell voodoo to do this? You can do the job in pure Perl. Seems like I had some fun with this a long time ago.
#!/usr/bin/perl -wT use strict; my $pid1=fork(); unless($pid1) { # First child my $stdout_file = 'child1_stdout.log'; my $stderr_file = 'child1_stderr.log'; local(*STDERR); local(*STDOUT); open(STDOUT1, '>'.$stdout_file) or die $stdout_file . ': ' . $!; open(STDERR1, '>'.$stderr_file) or die $stderr_file . ': ' . $!; open(STDOUT, ">&STDOUT1") or die "Couldn't redir stdout: $!"; open(STDERR, ">&STDERR1") or die "Couldn't redir stderr: $!"; system('cmd1'); close(STDOUT1); close(STDERR1); exit(); } my $pid2=fork(); unless($pid2) { # Same thing but call cmd2 instead of cmd1 exit(); } # Don't forget to wait for each child wait(); wait();
Update: (sigh) Ok, the STDOUT/STDERR redirection won't carry out to the system() call. If you weren't calling an external program, this would work. Using IPC::Open3 is probably the way to go. Using sockets to pass the data back to the parent will probably work better than anything involving the filesystem.

--isotope
http://www.skylab.org/~isotope/

In reply to Re: fork and stdout/stderr by isotope
in thread fork and stdout/stderr by smimp

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.