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

Re: capture STDOUT when some jerk opened STDOUT to /dev/tty

by davido (Archbishop)
on Jan 07, 2013 at 17:31 UTC ( #1012070=note: print w/ replies, xml ) Need Help??


in reply to capture STDOUT when some jerk opened STDOUT to /dev/tty

Capture::Tiny seems to handle it fine.

use Capture::Tiny qw( capture_stdout ); open STDOUT, '>/dev/tty' or die $!; my $output = capture_stdout { print "Hello world!\n"; }; print "<<<$output>>>\n";

...the output...

<<<Hello world! >>>

(as expected)

Update: ww has kindly reminded me that this is probably not a solution when you need to capture output of an external script. Apologies... and good luck! ;)


Dave


Comment on Re: capture STDOUT when some jerk opened STDOUT to /dev/tty
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (5)
As of 2014-07-26 13:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (176 votes), past polls