# first.pl
open (STDOUT, "| tee -a $LOGFILE") or die "Teeing off: $!\n";
####
# parent.pl
# Preserve the filehandler
open(OLDOUT, ">&STDOUT");
$LOGFILE="output.txt";
open LOG_FH, ">>$LOGFILE" ;
# disable perl buffering so that when you log messages on the screen to the logfile ,
select LOG_FH; $| = 1;
select STDOUT; $| = 1;
# Open STDOUT to log messages to file ...
open (STDOUT, "| tee -a $LOGFILE") or die "Teeing off: $!\n";
print "\nEnter Parent Process Input : ";
$p_input1=<>; chomp ($p_input1);
print LOG_FH "\nYou Entered : $p_input1";
close (LOG_FH);
close (STDOUT);
## redirect the file handler
open(STDOUT, ">&OLDOUT");
## No need the screen output to the log file
system("perl child.pl $LOGFILE");
####
# child.pl
$LOGFILE=$ARGV[0];
open FOUT, ">>$LOGFILE" ;
print "\nEnter the child process input : ";
$c_input1=;
print FOUT "\nYou Entered Child Input : $c_input1";
close (FOUT);