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

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;

Replies are listed 'Best First'.
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);


    % ./ 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);


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

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1060082]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2016-12-05 00:06 GMT
Find Nodes?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:

    Results (71 votes). Check out past polls.