Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re^8: capturing output of system call inside a thread

by BrowserUk (Patriarch)
on Sep 03, 2015 at 21:32 UTC ( [id://1140926]=note: print w/replies, xml ) Need Help??


in reply to Re^7: capturing output of system call inside a thread
in thread capturing output of system call inside a thread

In which case I want to capture STDOUT and STDERR of each worker "process".

And there is the source of my question: Why are you quoting "process"?

Either this is

  1. a real separate process;

    In which case you need to 'capture' the output from STDOUT and STDERR.

  2. Or it is just perl code running in a thread; and using the term 'process' is just misleading.

    In this case you don't need to 'capture' the output; you simply need to direct it to where you want it to go.

    Ie. If you are going to call a subroutine that normally writes to stdout and stderr; and you want that output to end up in a file of your choosing, then point stdout and stderr to that file before you call the subroutine:

    sub worker { local( *STDOUT, *STDERR ); open STDOUT, '>', 'my.log' or die $!; open STDERR, '>&STDOUT' or die $!; unmodifiable(); ## call the code that produces the output; it'll e +nd up in my.log ## the effects of the redirection get cleaned up automatically whe +n the worker ends. }

With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority". I knew I was on the right track :)
In the absence of evidence, opinion is indistinguishable from prejudice.
I'm with torvalds on this Agile (and TDD) debunked I told'em LLVM was the way to go. But did they listen!

Replies are listed 'Best First'.
Re^9: capturing output of system call inside a thread
by that_guy (Novice) on Sep 04, 2015 at 12:59 UTC
    Thanks for the answer. Your solution doesn't work. Output of the program run by system call still is being printed to the screen and not to the log file. Perhaps you should have spend less time on being a pedantic prick and spend 5 seconds on actually running the code you provided.
      . Your solution doesn't work. Output of the program run by system call still is being printed to the screen and not to the log file.

      It would. The solution I posted (as I clearly identified in the post), will only work for perl code running in the current process.

      You need the second part for external processes; but we never got that far.

      Its actually very trivial; but now you'll have to make that discovery for yourself won't you.

      (That's the trouble with shills; they so quickly self identify.)


      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority". I knew I was on the right track :)
      In the absence of evidence, opinion is indistinguishable from prejudice.
      I'm with torvalds on this Agile (and TDD) debunked I told'em LLVM was the way to go. But did they listen!
      A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2024-04-19 22:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found