1。要给 Python.exe所在目录添加权限,IIS_IUSRS,读取,执行;
2。PHP中要用 Python.exe 的绝对路径;
test.php:
$cmd1 = "python test.py 2>&1";
$cmd2 = "C:/.../python.exe test.py 2>&1";
echo $cmd1."<br>";
$output1 = shell_exec($cmd1);
$output2 = exec($cmd1, $array, $ret);
echo iconv('GB2312', 'UTF-8', $output1).'<br>';
echo 'array='.iconv('GB2312', 'UTF-8', implode("-",$array)).'<br>';
echo 'ret='.$ret.'<br>';
echo '<br>';
echo $cmd2."<br>";
$output3 = shell_exec($cmd2);
$output4 = exec($cmd2, $array, $ret);
echo iconv('GB2312', 'UTF-8', $output3).'<br>';
echo 'array='.iconv('GB2312', 'UTF-8', implode("-",$array)).'<br>';
echo 'ret='.$ret.'<br>';
test.py:
print('15')
test.php 执行结果:
python test.py 2>&1
'python' 不是内部或外部命令,也不是可运行的程序 或批处理文件。
array='python' 不是内部或外部命令,也不是可运行的程序-或批处理文件。
ret=1
C:/.../python.exe test.py 2>&1
15
array='python' 不是内部或外部命令,也不是可运行的程序-或批处理文件。-15
ret=0
另:
IIS 直接响应 http 请求执行 *.py ,在 服务器管理器,处理程序映射,添加 模块映射,
请求路径:*.py
可执行文件:C:/.../python.exe %s %s
模块:CgiModule