Log to file output of an exec() command tr

2019-08-28 09:27发布

I have a php script to convert PDF files to images using imagick.

It works on my local box but in the production server it fails to execute the command but not sure about the reason because I can't see my command execution output.

No SSH access or to the admin panel.

In order to solve this I need to know how can I log to a text file the output of this command execution in the shell from my php script, so I can after the fail download it by ftp and read it.

exec('convert -density 150 -quality 100 -sharpen 0x2.0 -background white -alpha remove ' . $file->getFileInfo()->getRealPath() . ' ' . $save_to, $result, $error);

$result variable I tried to print_r($result); and it just shows me Array ().

1条回答
乱世女痞
2楼-- · 2019-08-28 10:23

You can use shell_exec() which does same as exec() and will outputs for you the results to check where is the error by doing it this way.

$error = shell_exec('convert -density 150 -quality 100 -sharpen 0x2.0 -background white -alpha remove ' . $file->getFileInfo()->getRealPath() . ' ' . $save_to . ' 2>&1');

print_r($error);

exit;
查看更多
登录 后发表回答