Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

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

by Athanasius (Chancellor)
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

Replies are listed 'Best First'.
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?
[stevieb]: I don't know what you mean. I write the code in C/C++ that accesses the ICs per the datasheet, wrap it for Perl, then use them. My code ensures that the functions/methods from Perl do the right thing for the chips/sensors etc
[stevieb]: At least that's what I'm working on right now. I've also been updating my automated test software Test::BrewBuild so it handles this work properly. It's not really easy meshing high level languages with low-level hardware :)

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (5)
As of 2017-06-25 23:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How many monitors do you use while coding?















    Results (572 votes). Check out past polls.