简体   繁体   English

PHP shell_exec 在 python 命令行上没有响应

[英]PHP shell_exec is not responding on python command line

Hi I am running shell_exec on my PHP Application, Here is the code,嗨,我正在我的 PHP 应用程序上运行shell_exec ,这是代码,

$path = "C:/scripts/";
chdir($path);
$py_commonscript = 'python Common_Script.py';
$exec = shell_exec($py_commonscript);

echo "<pre>$exec</pre>";

This code doesn't give any result and does not generate a file.此代码不给出任何结果,也不生成文件。 When I tried running manually on the command line it is working and was able to generate a file.当我尝试在命令行上手动运行时,它正在工作并且能够生成一个文件。

I tried to execute this one below and it was able to display some result.我试图在下面执行这个,它能够显示一些结果。

$sample = shell_exec('ls -lart');
echo "<pre>$sample </pre>";

I am wondering why the command for $exec is not being triggered or run.我想知道为什么$exec的命令没有被触发或运行。

The most likely cause is that your PHP code isn't inheriting a %PATH containing python.exe.最可能的原因是您的 PHP 代码没有继承包含 python.exe 的 %PATH。 Try print getenv('PATH');尝试print getenv('PATH'); or just use the full path to python.exe in your command line.或者只是在命令行中使用 python.exe 的完整路径。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM