Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: running a cmd in background and capturing the output

by dasgar (Deacon)
on Oct 09, 2013 at 12:51 UTC ( #1057537=note: print w/ replies, xml ) Need Help??


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

Also i need to capture the output of this command to a file.

If you just need the command output in a file and not using it elsewhere in your script, you could just pipe the output of the command to the file named "file.txt". For example, your sample code appears to be calling the command du /usr/bin. You could modify it to be du /usr/bin > file.txt to pipe the STDOUT to a file.

If you do need the output in other parts of your script, then I personally would do this using threads. To go that route, I would probably create a subroutine that expects a directory as input and returns the output of the running the du command on that directory. Then you call that routine in a thread.

Just tossing out a few other suggestions.


Comment on Re: running a cmd in background and capturing the output
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1057537]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (8)
As of 2014-09-01 21:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite cookbook is:










    Results (17 votes), past polls