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.#!/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();
In reply to Re: fork and stdout/stderr
by isotope
in thread fork and stdout/stderr
by smimp
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |