Looking at perldoc -f system, note:
If there is more than one argument in LIST, or if LIST is an array with more than one value, starts the program given by the first element of the list with arguments given by the rest of the list. If there is only one scalar argument, the argument is checked for shell metacharacters, and if there are any, the entire argument is passed to the system's command shell for parsing
You are invoking system LIST
so the >
ends up being passed to dot
instead of being interpreted by the shell.
I would recommend that you keep using system LIST
because it is a little safer than passing everything through the shell. According to the docs, you can specify the output file by using the -o
option to dot
, so do that.
If you really want to dot your is and cross your ts (pun not intended), then you can use:
if ( defined $pngfile and $pngfile ne '') {
my @args = (dot => '-Tpng', $dottmpfile, "-o$pngfile");
if ( system @args ) {
warn "'system @args' failed\n";
my $reason = $?;
if ( $reason == -1 ) {
die "Failed to execute: $!";
}
elsif ( $reason & 0x7f ) {
die sprintf(
'child died with signal %d, %s coredump',
($reason & 0x7f),
($reason & 0x80) ? 'with' : 'without'
);
}
else {
die sprintf('child exited with value %d', $reason >> 8);
}
}
warn "'system @args' executed successfully\n";
unlink $dottmpfile;
}