I wrote a routine to "safely" execute some command, and I wanted to capture STDOUT and STDERR in string variables using open(STDOUT, '+<', \$stdout)
and similar for STDERR.
I verified via print "Test\n"
and print STDERR "Test2\n"
that the redirection works inside the routine (I can find the outputs in $stdout
and $stderr
).
However when I run the command through system()
(Perl's version), the output still goes to the terminal.
So I wonder: Is opening a scalar value available for Perl's own I/O only?
And if so, how would I capture the STDOUT and STDERR from the system()
call without using temporary files (having their own issues)?
(I've seen https://stackoverflow.com/a/109672/6607497 already)
The preferred solution (if such exists) should use as few extra packages as possible, and it should run with SLES 12 or SLES 15 (openSUSE Leap 15.2). Those distributions only offer a limited set of Perl modules.