Doing
system('downloadImage', '-url', $url, '>', $log)
in Perl is the same as doing
'downloadImage' '-url' "$url" '>' "$log"
in the shell. This executes downloadImage
with four arguments, one of which is >
. The shell command you were trying to execute is the following:
'downloadImage' '-url' "$url" > "$log"
If you want to execute that shell command, you first need a shell. The following is how you should achieve this:
use String::ShellQuote qw( shell_quote );
my @cmd = ('downloadImage', '-url', $url);
my $shell_cmd = shell_quote(@cmd) . ' >' . shell_quote($log);
system($shell_cmd); # Short for system('/bin/sh', '-c', $shell_cmd);
However, there are lots of downsides to using a shell. Here are some alternatives:
use IPC::Open3 qw( open3 );
my @cmd = ('downloadImage', '-url', $url);
{
open(local *CHILD_STDIN, '<', '/dev/null')
or die("Can't open \"/dev/null\": $!\n");
open(local *CHILD_STDOUT, '>', $log)
or die("Can't create \"$log\": $!\n");
my $pid = open3('<&CHILD_STDIN', '>&CHILD_STDOUT', '>&STDERR', @cmd);
waitpid($pid, 0);
}
or
use IPC::Run3 qw( run3 );
my @cmd = ('downloadImage', '-url', $url);
run3(\@cmd, \undef, $log);
or
use IPC::Run qw( run );
my @cmd = ('downloadImage', '-url', $url);
run(\@cmd, '<', '/dev/null', '>', $log);