Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: IPC::Cmd pipe array

by runrig (Abbot)
on Oct 28, 2013 at 22:38 UTC ( #1060082=note: print w/ replies, xml ) Need Help??


in reply to IPC::Cmd pipe array

IPC::Cmd's command option takes one string or array reference that specifies your command. Since you have a pipe "|" in your command(s), you are stuck with specifying a string. Or you can try IPC::Run

use IPC::Run qw(run); my @in = ("Test foo", "Test bar"); run [echo => -n => @in] , '|', [ sed => "s/(foo|bar)/pass/" ], '>', \m +y $out;


Comment on Re: IPC::Cmd pipe array
Download Code
Re^2: IPC::Cmd pipe array
by ag4ve (Monk) on Oct 29, 2013 at 14:38 UTC

    That sorta works (ie, it doesn't error), but not really:

    #!/usr/bin/env perl use strict; use warnings; use Data::Dumper; use IPC::Cmd qw/run/; my @in = ("Test foo", "Test bar"); print "In: " . Dumper(@in); @in = ("Test foo", "Test bar"); my @out = run(command => [echo => -n => @in] , '|', [ sed => -r => "s/ +(foo|bar)/pass/" ], '>', \my $out); print "Out: " . Dumper(@out); print "Redir: " . Dumper($out);

    Out:

    % ./t2.pl In: $VAR1 = 'Test foo'; $VAR2 = 'Test bar'; Out: $VAR1 = 1; $VAR2 = undef; $VAR3 = [ 'Test foo Test bar' ]; $VAR4 = [ 'Test foo Test bar' ]; $VAR5 = []; Redir: $VAR1 = undef;
      My code is using IPC::Run, not IPC::Cmd. Your's is still using IPC::Cmd.
        Ah, you're right. I'll look at converting (will probably be good since there's more written about IPC::Run anyway). Thanks
        #!/usr/bin/env perl use strict; use warnings; use Data::Dumper; use IPC::Run qw/run/; use IPC::Run qw(run); my @in = ("Test foo", "Test bar"); run [echo => -n => @in] , '|', [ sed => "s/(foo|bar)/pass/" ], '>', \m +y $out; print "Redir: " . Dumper($out);

        OUT:

        % ./t2.pl Redir: $VAR1 = 'Test foo Test bar';

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (10)
As of 2014-08-28 11:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (259 votes), past polls