robembra Posted December 28, 2009 Share Posted December 28, 2009 Hi, Im writing a simple script that backs up my databases, but the returned var from the system() function I dont understand it. Basically I want to validate my command to see if it has passed or failed, but when i check $output its either 0 for true and 2 for false. Im very confused and its probably because ive got the wrong end of the stick with how the output is returned. $command = "mysqldump --opt -h $dbhost -u $dbuser -p $dbpass $dbname | gzip > $backupFile"; system($command, $output); Please could anyone help me with this, its probably really simple but just cant get my head round it. Thanks Link to comment https://forums.phpfreaks.com/topic/186473-system-returned-output/ Share on other sites More sharing options...
trq Posted December 28, 2009 Share Posted December 28, 2009 What part don't you understand? You described the $output quite well. 0 is equal to true in Bash (which is likely your shell if your using Linux) while any other number is an error code. Link to comment https://forums.phpfreaks.com/topic/186473-system-returned-output/#findComment-984670 Share on other sites More sharing options...
robembra Posted December 28, 2009 Author Share Posted December 28, 2009 What part don't you understand? You described the $output quite well. 0 is equal to true in Bash (which is likely your shell if your using Linux) while any other number is an error code. Thanks...thats what I didnt understand "that 0 is equal to true in Bash". What is bash??? Well anyways i came up with this, is this correct $command = "mysqldump --opt -h $dbhost -u $dbuser -p $dbpass $dbname | gzip > $backupFile";system($command, $output); ($output == 0) or die("returned an error: $command"); Link to comment https://forums.phpfreaks.com/topic/186473-system-returned-output/#findComment-984677 Share on other sites More sharing options...
trq Posted December 28, 2009 Share Posted December 28, 2009 Bash is the default shell in most Linux distributions. Its also quite a powerful scripting language. Come to think of it, its not bash that would be returning you 0 for true but the mysql_dump command. Linux commands (built into the shell or otherwise) return 0 on success and some other number on failure. Link to comment https://forums.phpfreaks.com/topic/186473-system-returned-output/#findComment-984679 Share on other sites More sharing options...
robembra Posted December 28, 2009 Author Share Posted December 28, 2009 Bash is the default shell in most Linux distributions. Its also quite a powerful scripting language. Come to think of it, its not bash that would be returning you 0 for true but the mysql_dump command. Linux commands (built into the shell or otherwise) return 0 on success and some other number on failure. Helped alot and thanks for the quick replay! Link to comment https://forums.phpfreaks.com/topic/186473-system-returned-output/#findComment-984682 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.