phpexec()函数不工作,并且没有引发错误


php exec() function not working and not throwing error

我正试图让exec()函数从pdftk的命令中归档,但它都不起作用,而且我不知道如何在抛出错误时捕获错误。

我试过了:

$output = array();
$return_var = -1;
exec('pdftk RabiesVacCert.pdf fill_form vac.fdf output vaccine_cert.pdf flatten',$output,$return_var);
if ($return_var === 0) {
    //Record the success
}else{
    throw new 'Exception(implode("'n", $output));
}

和:

$output = array();
$return_var = -1;
exec("pdftk /full/path/to/folder/where/class/is/RabiesVacCert.pdf fill_form /full/path/to/folder/where/class/is/vac.fdf output /full/path/to/folder/where/class/is/Shotsvaccine_cert.pdf flatten",$output,$return_var);
if ($return_var === 0) {
    //Record success
}else{
    throw new 'Exception(implode("'n", $output));
}

什么也没发生。你知道我用exec()做错了什么吗?或者我如何显示错误?运行在Ubuntu 14.04上,它可以通过服务器上的命令行正常工作。

我把它改成了shell_exec(),现在它工作得很好。

shell_exec

通过shell执行命令,并以字符串形式返回完整的输出。

请参阅文档。