run.pl
use strict; use warnings; use IPC::Run qw(run); my($wtr, $rdr, $err); my @cmd = qw(script); my $pid = fork; my $timvariable = 7; unless($pid) { setpgrp; run \@cmd, '>>', "out.txt", '2>>', "err.txt"; } print "Child process id:$pid\n"; for(my $i =0;$i <= $timvariable ; $i++) { sleep(1); print "Parent is waiting to obtain the file which was created by c +hild process\n"; } kill 9,"-$pid"; kill 9,"$pid";
script
#!/usr/bin/perl use POSIX; while(1) { sleep(1); print "I am running\n"; my $pid = fork; print "Process group Id:",getpgrp $pid,"\n"; unless($pid) { while(1) { sleep(2); print "Process group Id in child:",getpgrp getpid(),"\n"; print "I am child and I'am running\n"; } } }
In the above code out.txt contains only the string that is printed by its child but it is not printing the strings that was printed by child of its child.
refer out.txt
I am runningHere I want to print the characters "I am child and I'am running". How to solve this issue?. Thanks in advance
In reply to Redirect the process group stdout to parent by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |