- the actual output (stdout) which would be "blah",
- any error output (stderr) which would be "" ie; NULL or empty,
- and the return code which would be "0";
my $result = `echo blah`; # captures "blah" into $result
my $result = system("echo blah"); # captures the return value of echo into $result
..and i stopped paying attention about there.
Suffice to say, no method i knew about allowed me to capture them all at the same time. Until i discovered IO::CaptureOutput. Check out this foo;
$ cat ./perl.system.calls.sh #!/usr/bin/perl use strict; use IO::CaptureOutput qw/capture_exec/; my @cmd= "echo blah"; my ($stdout, $stderr, $success, $exit_code) = capture_exec( @cmd ); chomp($stdout); print "running '@cmd'\n"; print "stdout = $stdout\n"; print "stderr = $stderr\n"; print "success = $success\n"; print "exit_code = $exit_code\n"; $ ./perl.system.calls.sh running 'echo blah' stdout = blah stderr = success = 1 exit_code = 0
So now i can trap these in my code and handle them each as i see fit. It means better error handling and software that runs (and stops!) how and when one might want it to. And that's cool.