开发者

Correct path to run python script with php from cgi-bin folder

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'开发者_StackOverflowd and is executable (I have tested)


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'); 
?>


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).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜