in reply to Re: IPC::Cmd pipe array
in thread IPC::Cmd pipe array

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;

Replies are listed 'Best First'.
Re^3: IPC::Cmd pipe array
by runrig (Abbot) on Oct 29, 2013 at 16:54 UTC
    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';