http://www.perlmonks.org?node_id=1057604


in reply to running a cmd in background and capturing the output

If you need the output of the command in your program (you presumably do), then you have to wait for this command to complete and using back ticks is probably the best solution, even if it is arguable that this is not exactly background.

Replies are listed 'Best First'.
Re^2: running a cmd in background and capturing the output
by PBeginner (Initiate) on Oct 10, 2013 at 05:21 UTC

    Thanks to All for the suggestions, but i tried this way and its working good.

    my $myproc = Proc::Simple->new(); $myproc->redirect_output ("/outcome1.txt"); $myproc->start(\&disk_use,"/usr/bin"); my $running = $myproc->poll(); ##to chk if process is still running. my $pid= $myproc->pid; my $bk_id1=$pid; sub disk_use { my $path=shift; my $total_usage=du("$path"); print "total disk uasge is $total_usage\n"; }

    Its working:)