尝试 运行 python PHP 中的脚本

Trying to run python script in PHP

我正在尝试使用以下命令在 perl 脚本中 运行 Python 脚本:

system("python3 script.py -d http:\/\/site.com --no-interaction");

qx/python3 script.py -d http:\/\/site.com --no-interaction/;

在操作系统的命令行上,Python 脚本执行,但是当我从 PHP 应用程序进行调用时,perl 工作,但 python 脚本不执行没用。

您是否从 Perl 端收到任何错误消息? 您的 PHP/Perl 脚本运行的位置可能与 script.py 所在的位置不同。尝试使用 Python 脚本的完整路径。还要仔细检查 python3 是否在您的 $PATH 中。

例如: -> 猫 /home/me/python/script.py

print("This line will be printed.")

-> cat /home/me/perl/pytest.pl

#!/bin/env perl
print "From perl:\n";
system ("python3 /home/me/python/script.py");
cd /home/me/perl/
ksh
whence python3
"/usr/bin"
pytest.pl
"From perl:
 This line will be printed."