in reply to system() Creating Different Results than Commandline Operation.

By the way, what's with ">/dev/null" on Windows? That should be ">nul".

It's actually simpler to make it portable:

sub system_no_output { my $mode = shift; open(my $chld_in, '<&', *STDIN) or die($!); my $chld_out = '>&STDOUT'; my $chld_err = '>&STDERR'; open($chld_out=undef, '>', devnull()) or die($!) if $mode & 1; open($chld_err=undef, '>', devnull()) or die($!) if $mode & 2; my $pid = open3($chld_in, $chld_out, $chld_err, @_) or die($!); return waitpid($pid, 0); }

Replies are listed 'Best First'.
Re^2: system() Creating Different Results than Commandline Operation.
by kazeits (Initiate) on Apr 06, 2009 at 18:02 UTC
    due to major changes to gcov over versions it needs to be opened to see what version is installed. the code makes a call to:
    if (system_no_output(3, $gcov_tool, "--help") == -1)
    using your solution to rewrite system_no_output seems to hang waiting for gcov to return. I don't understand why.

      -1 is not a valid value for $?, so it's a bug to expect system_no_output to return -1.

      If you want -1 when system fails and $? otherwise, you want:

      # Your version $result = system(@_);
      # My version my $pid = open3($chld_in, $chld_out, $chld_err, @_) or return -1;

      your solution to rewrite system_no_output seems to hang waiting for gcov to return

      system waits for the child to return, so I did the same.