Viewed   92 times

I am trying to run a Python program using PHP. Here's the code

$command = '/usr/local/bin/python file';
$temp = exec($command, $output);

This works through the command line but not while running it through the browser. I am using Apache so probably it needs the right privileges? I am pretty new to Linux and have no idea how to get this working.

Any help would be appreciated!

Edit 1:

Tried to use proc_open but nothing happens. I gave the full path to the script. Made the script executable but no luck. Any other things I can try on the server? (It's a CentOS 5)



You need to pass the full path to the script and you also need to make sure that the script is readable by the user running the web server (which means every directory in the path must be +x to the web user).

Monday, November 7, 2022

another option, you can set path to interpreter in 1st line of script


but you need make executable

chmod +x path_to_file/

and run from php as


P.S. be attentive administrators sometimes disable exec function on servers for safety. disable_functions="popen,exec,system,passthru,proc_open,shell_exec" ....

Sunday, November 27, 2022

Capture the stdout and stderr of the subprocess:

from subprocess import Popen, PIPE

proc = Popen(['/var/www/scripts/', 'arg1', 'arg2'], stdout=PIPE, stderr=PIPE)
stdout, stderr = proc.communicate()
Thursday, December 8, 2022

I'd say you just need to prepend 'call' to your activate.bat invocation, to ensure that the current batch file is resumed after activate is executed:

call %~dp0envScriptsactivate.bat

Consider doing the same for deactivate.bat. Furthermore, if you want to ensure that the current cmd.exe environment is not polluted by a call to your batch file, consider wrapping your commands in a setlocal/endlocal command pair.

Friday, August 19, 2022

I finally found a way to do this. If I create a zip file, I must create at the root of the zip. Thus, it is possible to launch the script inside the main and call if from bash with the following command :


This command will run the file! :)

Then I can create .command file to launch the script with proper parameters.

You can also put some code in the file to give you more flexibility if you need to pass arguments for example.

ex: python buildProject

The reference documentation is here:

Sunday, September 25, 2022
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :