$? returns the result code from the last system() call or backtick operation, I believe, so you can both capture output and process result codes.
Example:
Output:#!/bin/perl # first command deliberately generates an error.... print `rubbish`; print "Rubbish Result: $?\n"; # this command should succeed print "ls Output:\n"; print `ls -l`; print "ls Result: $?\n";
Note the first output of $? is -1 (an error), whilst the second is 0 (success)Rubbish Result: -1 ls Output: total 10 -rw-r--r-- 1 Userid Domain Users 1242 Oct 30 10:04 1.txt -rw-r--r-- 1 Userid Domain Users 1531 Oct 30 10:04 2.txt -rwxr-xr-x 1 Userid Domain Users 351 Oct 30 10:48 test.pl -rwxr-xr-x 1 Userid Domain Users 108 Oct 31 14:21 var.pl ls Result: 0
In reply to Backticks and exit status
by space_monk
in thread Run multiple shell commands on the same perl script
by Daral
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |