Re: system v backticks



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
.



Relevant Pages

  • Hard Disk Not Mounting
    ... I want to port WinCE ... -USBD:OpenPipe success, hPipe = D039E210 ... HidParse: 'Preparing to Allocate memory ... DEVICQueuedPipe::CheckForDoneTransfers - failure on TD 0xd05858a0, ...
    (microsoft.public.windowsce.platbuilder)
  • Re: (Kinda) O/T: The Varieties Of Rooting Experience
    ... Koubek on his first rubber (was 2-4 in the fifth until Koubek choked the break ... series (he already gave the surprise winning his #2 vs #1 rubber against ... Failure was mourned, but in a low-key, philosophical tone, as ... Occasional success was unspeakably sweet, ...
    (rec.sport.tennis)
  • Re: A simple parser
    ... success, EXIT_FAILURE for failure. ... indicate *success* to the calling environment. ... It's often possible to define return values other than the standard ... Other error codes could be syntax error in ...
    (comp.lang.c)
  • Re: How to determine who changed permissions on a directory?
    ... Audit Account Logon events - Success, Failure ... Computer: SERVER1 ...
    (microsoft.public.security)
  • [PATCH 08/12] hdaps: Add explicit hardware configuration functions
    ... * Returns zero on success and negative error code on failure. ... Can sleep. ...
    (Linux-Kernel)