I want to execute Python script from PHP file. I am able to execute simple python script like:
print("Hello World")
但是当我想执行以下脚本时,什么也没有发生
from pydub import AudioSegment
AudioSegment.converter = "/usr/bin/ffmpeg"
sound = AudioSegment.from_file("/var/www/dev.com/public_html/track.mp3")
sound.export("/var/www/dev.com/public_html/test.mp3", format="mp3", bitrate="96k")
当我从终端执行相同的脚本时,它能够正常工作。以下是我的 PHP 脚本:
and same script works fine when I execute it from terminal. here is my php script:
$output = shell_exec("/usr/bin/python /var/www/dev.com/public_html/index.py");
echo $output;
我也尝试了以下方法,但没有成功:
$output = array();
$output = passthru("/usr/bin/python /var/www/dev.com/public_html/index.py");
print_r($output);
请帮助我
putenv("VARIABLE=value");
来设置它们。 - Chris Wheeler