in reply to how to retrieve the error message returned by the system command

If you're running on a *nix OS, you could redirect the standard error to a temporary file and then parse the contents if it the file exists.

my $ERR_FILE = q{/tmp/error_message.txt}; qx{COMMAND 2>$ERR_FILE}; if ( -f $ERR_FILE ) { open my $FH, '<', $ERR_FILE; my @err_msg = <$FH>; close $FH; unlink $ERR_FILE or die "Can't remove $ERR_FILE: $!"; }
--njcodewarrior
  • Comment on Re: how to retrieve the error message returned by the system command
  • Download Code

Replies are listed 'Best First'.
Re^2: how to retrieve the error message returned by the system command
by swampyankee (Parson) on Mar 27, 2006 at 17:19 UTC

    You can do the same thing (with pretty much the same syntax) on modern versions of Windows. I'd use File::Temp; and one of the mktemp family of functions to generate a name, but that's more a style issue than a real difference.

    emc

    " The most likely way for the world to be destroyed, most experts agree, is by accident. That's where we come in; we're computer professionals. We cause accidents."
    —Nathaniel S. Borenstein