I would like to invoke a script from my Perl code and capture its STDERR and STDOUT combined together.
I usually use capture from IPC::System::Simple but ti doesn't seem to allow capturing of STDERR.
You can redirect STDERR (file descriptor 2) to STDOUT (file descriptor 1) with 2>&1.
From perlop on the qx// operator:
Because backticks do not affect standard error, use shell file descriptor syntax (assuming the shell supports this) if you care to address this. To capture a command's STDERR and STDOUT together:
$output = `cmd 2>&1`;
On a POSIX system, you can do the following. On Windows, this would work in cygwin.
my @lines = capture("some command 2>&1");
However, if you want to distinguish STDERR lines from STDOUT lines, maybe you need to use IPC::Open3 or the mis-named IPC::Open3::Util.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With