Get return code and output from command in Perl

The universal solution for backticks, system(), etc is to use the ${^CHILD_ERROR_NATIVE} variable. See the perlvar perldoc: http://perldoc.perl.org/perlvar.html#%24%7b%5eCHILD_ERROR_NATIVE%7d

${^CHILD_ERROR_NATIVE} The native status returned by the last pipe close, backtick (`` ) command, successful call to wait() or waitpid(), or from the system() operator. On POSIX-like systems this value can be decoded with the WIFEXITED, WEXITSTATUS, WIFSIGNALED, WTERMSIG, WIFSTOPPED, WSTOPSIG and WIFCONTINUED functions provided by the POSIX module.


After backticks are run, the return code is available in $?.

$?

The status returned by the last pipe close, backtick (``) command, successful call to wait() or waitpid(), or from the system() operator. This is just the 16-bit status word returned by the traditional Unix wait() system call (or else is made up to look like it).

$output = `$some_command`;
print "Output of $some_command was '$output'.\n";
print "Exit code of $some_command was $?\n";