Perl: the Markov chain saw | |
PerlMonks |
Re: Capturing errors from backtickby davido (Cardinal) |
on Feb 26, 2020 at 16:12 UTC ( [id://11113445]=note: print w/replies, xml ) | Need Help?? |
If you look at the documentation in perlop for backticks it provides several strategies; shell redirection of STDERR to STDOUT, swapping STDERR and STDOUT, and even just writing STDERR to a file that you can look at later. It's entirely possible none of these are convenient for your use case. I'd recommend instead going to a module like Capture::Tiny where your code would look something like this:
I used the list form of system as well, to avoid exposing $url to the shell; this is a bit of a safety best practice. You can see here that using the capture function you can run your external call as a system call, and then capture STDOUT, STDERR, and the exit code into distinct variables that you can then inspect after the call. The Capture::Tiny module consists of less than 430 lines of well-tested code, and has no non-core Perl dependencies, so it should be quite easy to install. Dave
In Section
Seekers of Perl Wisdom
|
|