code_junkie

How can I read stderr when a command execution fails in Perl?

Nov 12th, 2011
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.45 KB | None | 0 0
  1. my @lines = `/usr/local/bin/diff -udr "$expected_file" "$gen_file"`;
  2.  
  3. if ($? != 0)
  4. {
  5. print ERRFILE "Diff between $expected_file and $gen_file failedn";
  6. return $diff_err;
  7. }
  8.  
  9. use IO::CaptureOutput 'qxx';
  10.  
  11.  
  12. my ($stdout, $stderr, $ok) =
  13. qxx( qq(/usr/local/bin/diff -udr "$expected_file" "$gen_file") );
  14.  
  15. if (! $ok)
  16. {
  17. print ERRFILE "Diff between $expected_file and $gen_file failedn";
  18. return $stderr;
  19. }
  20.  
  21. my @lines = split /n/, $stdout;
Add Comment
Please, Sign In to add comment