Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Re: running a cmd in background and capturing the output

by dasgar (Priest)
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.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1057537]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (3)
As of 2018-01-19 06:54 GMT
Find Nodes?
    Voting Booth?
    How did you see in the new year?

    Results (216 votes). Check out past polls.