0
votes

I want to run python script 'test.py' from my cgi-bin directory on my webserver. the cgi-bin directory is at 'www/cgi-bin/'. The python scrip is in that directory. The php code I'm executing is at 'www/html/website/index.php'.

what is the correct path that goes here ------> exec('path');

TYVM

edit: My python script has been chmod +x'd and is executable (I have tested)

2
Why do you want to run your Python CGI script via PHP? This is a very unorthodox thing to do... - Ignacio Vazquez-Abrams

2 Answers

0
votes

Assuming the PHP script is in the same directory as the "www" directory.

<?
    exec('./www/cgi-bin/test.py'); 
?>

or without chmoding, you can run it through Python

<?
    exec('python ./www/cgi-bin/test.py'); 
?>
0
votes

Your PHP code is executing in the www/html/website/ directory then. You need to go up two directories (arriving in the www/ directory), then go down to the cgi-bin/ subdirectory. So this should work:

exec('../../cgi-bin/test.py');

Note that this is relying on the current work directory being the PHP script directory. This might not always be the case, particularly if something in the PHP script changes the current work directory explicitly or simply if this PHP script is included from a different script. So it is better to use absolute paths (e.g. put the absolute path of the base directory into a config file).