note 23790 added to function.system
| From: | salinasj at txcyber dot com | Date: | Sun, 28 Jul 2002 23:16:01 +0000 |
| Subject: | note 23790 added to function.system | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-33842@lists.php.net to get a copy of this message | ||
Assuming that 0 = false and 1 = true doesn't always work.
If you are having problems trying to figure out why the system() function sometimes seems to return
true/false backwards, you should verify the return codes of the system command you are executing.
For example:
<?
$cmd="/usr/bin/mysql -h$host -u$user -p$pass -e'$command'";
$res = (system($cmd)) ? true : false;
print $res;
?>
// if the command fails, 1 will be printed.
// if the command works, 0 will be printed.
<?
if(system($cmd) === false) {
print "Failed";
} else {
print "Success";
}
?>
// outputs Success when it fails
This is due to mysql returning 0 if no errors have occurred
and returning 1 if errors have occurred.
Might be good to look up returned error codes of the system command you are executing to make sure
you are branching correctly.
--
http://www.php.net/manual/en/function.system.php
http://master.php.net/manage/user-notes.php?action=edit+23790
http://master.php.net/manage/user-notes.php?action=delete+23790
http://master.php.net/manage/user-notes.php?action=reject+23790