Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
453 views
in Technique[技术] by (71.8m points)

shell exec - PHP shell_exec is not responding on python command line

Hi I am running shell_exec on my PHP Application, Here is the code,

$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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The most likely cause is that your PHP code isn't inheriting a %PATH containing python.exe. Try print getenv('PATH'); or just use the full path to python.exe in your command line.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...