Jump to content

system() returned output


robembra

Recommended Posts

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

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");

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.

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!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.