【发布时间】:2017-08-23 14:09:55
【问题描述】:
我正在尝试执行 Python 脚本作为对我的 PHP 代码的响应。这就是我的 Python 脚本的样子(当然是为了测试目的):
#!/usr/bin/env python
# -*- coding: utf-8 -*-
print 'test'
import sys
sessionDir = sys.argv[1][:-14]
sys.stdout = open(sessionDir + 'output.txt','w')
print sessionDir
sys.stdout.close()
我的 PHPCode 如下所示:
global $calculationDir, $calculation, $userFilesDir;
//$pythonExe = '"D:\\WinPython-64bit-2.7.10.3\\WinPython Command Prompt.exe" python ';
//$pythonExe = 'abaqus python ';
$pythonExe = 'python ';
$scriptFile = '"'.$_SERVER['APPL_PHYSICAL_PATH'].substr($calculationDir,2).$calculation.'\\python\\test.py" ';
$dataFile = '"'.$userFilesDir.$_SESSION['user'].'\\'.$calculation.'\\'.$this->sessionID.'\\Parameters.dat"';
$command = escapeshellcmd($pythonExe.$scriptFile.$dataFile);
echo passthru('ipconfig').'<br>';
$output = passthru($command);
echo $output.'<br>';
passthru($command) 不执行 python 脚本。如果我在命令控制台中手动键入命令行,它就可以正常工作。出于测试目的,我还打印了我的 ipconfigjust 以测试该功能是否有效 - 它确实有效。
正如您在我的代码中看到的,我有三种方法来调用 python 解释器。第一个是可移植的python版本,第二个是abaqus python,第三个是python的系统路径。这是棘手的部分。该脚本确实适用于 abaqus python,但其他两个 python 均不适用。
我还尝试了exec(), shell_exec(), system() 而不是passthru(),这并没有改变任何东西。用户还被授予对 python 脚本的完全访问权限。我错过了什么?你有什么想法我应该尝试看看是否执行了python脚本? (是否缺少需要我提供的信息?)
编辑:
它在 IIS 7 Web 服务器上运行。 - 我通过 Windows File-Explorer 和 IIS-Programm(针对整个文件夹)更改了 python 脚本的权限。
【问题讨论】: