【发布时间】:2016-01-14 15:01:44
【问题描述】:
我有这行代码来执行后台任务(将几个 png 转换为 jpg)
exec("nohup path/to/php path/to/convertToJpg.php >> path/to/convert_to_jpg.log > /dev/null &");
现在我正在编写convertToJpg.php 脚本,但我不知道如何从那里输出信息以便将其登录到convert_to_jpg.log。
当我尝试 google 时,我想到的只是如何从 exec 或 shell_exec 调用 php 脚本,因为用于描述这两种情况的词几乎相同。
澄清
在将代码复制到 SO 时,我的代码中有一个额外的引用。我已经修好了。在我的原始代码中,convertToJpg.php 被按预期调用,由 error_logs 确认,放入其中进行检查。
一些答案指向exec() 中的$output 参数。据我了解,这完全违背了使用>> path/to/convert_to_jpg.log 进行shell 重定向的目的。
我的问题不是如何从exec() 命令获取输出,而是我使用什么代码从convert_to_jpg.log 实际输出(动词)
更多说明
如果我打电话
exec("nohup path/to/php path/to/convertToJpg.php >> path/to/convert_to_jpg.log > /dev/null &");
或
$results = shell_exec("path/to/php path/to/convertToJpg.php > /dev/null");
echo $results;
或
$results = "";
exec("path/to/php path/to/convertToJpg.php > /dev/null", $results);
print_r($results);
不管是哪一个。
这里是convertToJpg.php
<?php
echo "Will this be in $results?"; // No, this did not end up in results.
error_log("error logs are being logged, so I know that this php file is being called");
//I have tested echo, but that does not work.
//What php function do I use so that a string will be captured in the $output of an exec() call?
?>
【问题讨论】:
-
鉴于这是完全无效的 php,它根本不会运行...
-
什么是无效的php?我的还是之前明显删除了他的评论的评论者?
-
您在 exec() 调用中删除了额外的
"...
标签: php shell shell-exec