in reply to Capturing remote command output to a file
It seems you were trying to use system safely by avoiding the shell by using it's multi-argument form, then abandoned your efforts and introducing other errors in the process. Solutions:
# Not portable to Windows sub shell_quote { my ($arg) = @_; $arg =~ s/'/'\\''/g; $arg = "'$arg'"; return $arg; } my $cmd = join ' ', map shell_quote($_), @CreateList; system("$cmd > data/test.txt") and die;
open(my $fh_out, '>', 'data/test.txt') or die; open(my $pipe, '|-', @CreateList) or die; print $fh_out $_ while <$pipe>;
use IPC::Open2 qw( open2 ); open(my $fh_out, '>', 'data/test.txt') or die; my $pid = open2('>&'.fileno($fh_out), '<&STDIN', @CreateList); waitpid($pid, 0);
|
|---|