Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
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 surveying the Monastery: (13)
As of 2015-07-06 12:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (74 votes), past polls