Python脚本未使用PHP执行

时间:2019-04-17 12:29:57

标签: php python

Python命令未显示任何结果。它只是显示空白。

whoami命令成功运行。 但是python存在一些问题。

PHP:

<?php

echo 'before<br />';

$my_command = escapeshellcmd('whoami');
$command_output = shell_exec($my_command);
echo $command_output;

echo '<br />&nbsp;New Command<br />';

$my_command = escapeshellcmd('python test.py');
$command_output = shell_exec($my_command);
echo $command_output;

?>

Python:

echo "Hello World"

2 个答案:

答案 0 :(得分:0)

使用它:({{1}中的2>&1

shell_exec

$command_output = shell_exec('python path\test.py 2>&1'); echo $command_output; 是将流重定向到另一个文件描述符的语法->&是stdin,0是stdout,而1是stderr。

2是指进程的第二个文件描述符,即stderr。

2表示重定向。

>表示重定向的目标应与第一个文件描述符(即stdout)位于同一位置。

答案 1 :(得分:0)

我测试了您的代码。您的php代码有效,这是错误的python代码。

val.resize(20,' '); qDebug() << val; 的内容替换为:

test.py

如果您使用python3,或者:

print("Hello World")

如果您使用python2。

如果您从命令行(print "Hello World" )运行php脚本,您将看到python解释器引发的无效sintax错误。
当您可能在服务器上运行脚本时,应检查错误日志以查看错误。错误日志的位置取决于您的服务器,例如,我的apache 2 localhost服务器位于php myfile.php