从php触发的exec()命令的日志文件输出 [英] Log to file output of an exec() command triggered from php

查看:592
本文介绍了从php触发的exec()命令的日志文件输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个PHP脚本,可以使用imagick将PDF文件转换为图像。

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.

没有SSH访问或管理面板。

No SSH access or to the admin panel.

为了解决这个问题,我需要知道如何我从我的php脚本登录到一个文本文件,在shell中执行这个命令的输出,所以我可以在ftp下载失败后读取它。

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 变量我尝试 print_r($ result); ,它只显示我 Array()

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

推荐答案

您可以使用 shell_exec() ,它与 exec() ,并输出结果以查看错误在哪里通过这样做。

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;

这篇关于从php触发的exec()命令的日志文件输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆