Re: system v backticks
- From: japhy@xxxxxxxxxxxx (Jeff 'japhy' Pinyan)
- Date: Thu, 28 Jul 2005 00:03:10 -0400 (EDT)
On Jul 28, Keenan, Greg John (Greg)** CTR ** said:
sub getDate {
print "start date\n";
if ( system("/bin/date") ) {
print "can't get date\n";
exit(2);
}
print "finish date\n";
}
system() executes a command, and returns the shell's error code. 0 indicates success, non-0 indicates failure. It does NOT return the output. If output is produced from the program, it's printed to STDOUT.
sub getDate {
print "start date\n";
if ( `/bin/date` ) {
print "can't get date\n";
exit(2);
}
print "finish date\n";
}
Backticks execute a command and return its output. Since the return value is true in this case, the if() statement's condition is true, and you call exit().
If system() or ``s fail, you should check $! to see the error message.
-- Jeff "japhy" Pinyan % How can we ever be the sold short or RPI Acacia Brother #734 % the cheated, we who for every service http://japhy.perlmonk.org/ % have long ago been overpaid? http://www.perlmonks.org/ % -- Meister Eckhart .
- References:
- system v backticks
- From: Greg John ** CTR ** Keenan
- system v backticks
- Prev by Date: Re: system v backticks
- Next by Date: RE: skip/delete lines with dup keys
- Previous by thread: Re: system v backticks
- Index(es):
Relevant Pages
|