【发布时间】:2021-11-08 19:21:54
【问题描述】:
我的目标是通过单击 HTML(PHP) 按钮运行具有不同参数的不同 Python 函数。 当我在终端中执行命令时,一切正常(灯亮)
# terminal
python3 -c 'from lights import *; lights.turn_on_group("bath")'
但是当我尝试在 PHP 中运行相同的命令时,什么也没有发生(空白页)。
# test.php
$cmd = "python3 -c 'from lights import *; lights.turn_on_group(\"bath\")'";
$command = escapeshellcmd($cmd);
$output = shell_exec($command);
有人知道如何解决这个问题吗?
【问题讨论】:
-
你能把这个
print "<pre>$output</pre>";代码添加到php文件中,这样我们就可以清楚地看到它是什么问题了。 -
@Orhan 有一个空输出 -> ""