Run a Python script from PHP

Run a Python script from PHP


I need to run a Python file after clicking on a button. PHP’s shell_exec function works fine for commands like ‘ls’ but I’m not able to pass arguments like -
python to that function.
Thanking you in advance


Why can’t you pass arguments? It should execute whatever you pass it.


I can pass the arguments

This command if echoed doesn’t give any output.
I have tried variants like passing the complete path to the file or the python interpreter or both



$output = shell_exec("python");

shows nothing? If you just run python in the terminal, does it produce output?


It’s giving the correct output. Thanks!:slight_smile:



May I ask a question?


If it’s directly related to this thread, ask away. If it isn’t, open a new thread and ask there, don’t reopen dead threads unless you need to.