I am trying to execute a Python Script as a response to my PHP code. This is what my Python Script looks like (for testing purposes ofcourse):
#!/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()
My PHPCode looks like the following:
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>';
The passthru($command) does not execute the python script. The command line works just fine if I type it in the command console by hand. For testing purposes I also print my ipconfigjust to test if the function works - which it does.
As you can see in my code I have three approaches to call the python intepreter. First is a portable python version, second is abaqus python and third is the systempath to python. And here is the tricky part. The script does work with abaqus python but neither of the other two pythons.
I also tried exec(), shell_exec(), system() instead of passthru(), which did not change anything. The users are also granted full access on the python script. What am I missing? Do you have any Ideas what else I should try to see if the python script is executed? (Is there a lack of information you need me to provide?)
Edit:
It runs on an IIS 7 Web-Server. - I changed the permission for the python Script via the Windows File-Explorer and also via the IIS-Programm (for the whole folder).