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

Re: Using IPC::Open3 instead of backtick operator

by fishy (Friar)
on Jun 09, 2016 at 18:58 UTC ( [id://1165249]=note: print w/replies, xml ) Need Help??


in reply to Using IPC::Open3 instead of backtick operator

Hi rcrews,

without any critics, my programs use IPC::Cmd:

use strict; use warnings; use IPC::Cmd qw( run ); my $tool = 'tar'; my $cmd = [ $tool, 'xvzf', $in_filename ]; my $buffer = ''; my @out = run( command => $cmd, buffer => \$buffer, verbose => 1 ); die "Error extracting $in_filename: $buffer" unless $out[0];

Have fun!

Replies are listed 'Best First'.
Re^2: Using IPC::Open3 instead of backtick operator
by ikegami (Patriarch) on Jun 10, 2016 at 15:58 UTC

    This is the equivalent of doing no warnings;. It simply silences the message without addressing the issue (preventing error log from being filled with child's STDERR output). If your goal is simply to circumvent perlcritic, it provides far better ways of doing that.

      Depending on configuration, IPC::Cmd will use either IPC::Run or IPC:Open3, so will capture STDERR as well as STDOUT.

      Called with 1 buffer, IPC::Cmd will put both STDOUT and STDERR in that buffer. Called in list context, it will return seperate buffers for STDOUT and STDERR.

        use strict; use warnings; use IPC::Cmd qw( run ); my $tool = 'tar'; my $cmd = [ 'perl', '-e', 'warn "TEST FAILED IF YOU SEE THIS\n"' ]; my $buffer = ''; my @out = run( command => $cmd, buffer => \$buffer, verbose => 1 );
        $ perl z.pl Running [perl -e warn "TEST FAILED IF YOU SEE THIS\n"]... TEST FAILED IF YOU SEE THIS

        However, one simply has to remove verbose => 1 to make this a solution.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1165249]
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: (3)
As of 2024-03-28 15:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found