I'm not sure what I'm doing wrong here (or why this is reporting success as I'm not getting any output). The end goal is to echo an array of iptables save data into iptables-restore:
#!/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); my @out = run(command => 'echo -n ', \@in , '| sed -r "s/(foo|bar)/pass/"'); print "Out: " . Dumper(@out);
Output:
In: $VAR1 = 'Test foo'; $VAR2 = 'Test bar'; Out: $VAR1 = 1; $VAR2 = undef; $VAR3 = []; $VAR4 = []; $VAR5 = [];
UPDATE:
IPC::Run does work as @runrig said - I just didn't notice -r got removed from said which changes the regex sed uses.
#!/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 => join("\n", @in)] , '|', [ sed => -r => "s/(foo|bar) +/pass/" ], '>', \my $out; print "Redir: " . Dumper($out);
In reply to IPC::Cmd pipe array by ag4ve
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |