如何检查 php 系统函数是否执行没有任何错误


How can i check if php system function executes wihtout any error?

<?php
    $command = "mysqldump -uroot -ppassword test --compact --skip-add-locks --skip-disable-keys --skip-set-charset --extended-insert=FALSE --add-drop-database --add-drop-table --routines --databases --triggers | gzip > test.sql.gz ";
    system ( $command );
?>

如何检查它是否执行没有错误?

$output = system ( $command , $return_var )

如果存在 $return_var 参数,则执行命令的返回状态将写入此变量。

$output成功时返回命令输出的最后一行。

你可以从系统函数PHP手册中学习。

它返回一个带有分辨率的字符串,所以试试这个:

$output = system ( $command );
if ($output == FALSE) { echo "error"; } else { echo $output; }