Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: How to output backtick or qx to a variable and STDOUT at the same time?

by Athanasius (Abbot)
on Nov 20, 2012 at 06:03 UTC ( #1004660=note: print w/ replies, xml ) Need Help??


in reply to How to output backtick or qx to a variable and STDOUT at the same time?

I’m not exactly clear on what you want, but the CPAN module Capture::Tiny will almost certainly meet your needs. For example (from the documentation):

($stdout, $stderr, $exit) = capture { system($cmd, @args); };

Update: For your specific example:

#!usr/bin/perl use strict; use warnings; use Capture::Tiny qw(capture); my ($stdout, $stderr, $exit) = capture { system('ls', '-l'); }; print "After the system call:\n"; print "\$stdout = $stdout\n"; print "\$stderr = $stderr\n"; print "\$exit = $exit\n";

Hope that helps,

Athanasius <°(((><contra mundum


Comment on Re: How to output backtick or qx to a variable and STDOUT at the same time?
Select or Download Code
Re^2: How to output backtick or qx to a variable and STDOUT at the same time?
by dr.jekyllandme (Sexton) on Nov 20, 2012 at 06:43 UTC
    Thank you! Looking over at Capture::Tiny's doc, I found tee. Which is exactly what I needed. Output both to STDOUT and store in a variable for later use.
    #!usr/bin/perl use strict; use warnings; use Capture::Tiny qw(capture tee); my ($stdout, $stderr, $exit) = tee { system('ls', '-l'); }; print $stdout;

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (7)
As of 2015-07-05 05:16 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 (60 votes), past polls