Run a Python script from PHP

Run a Python script from PHP
0.0 0

#1

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 qwerty.py to that function.
Thanking you in advance


#2

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


#3

I can pass the arguments
Example,
shell_exec(“python qwerty.py”)

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


#4

So,

$output = shell_exec("python qwerty.py");
var_dump($output);

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


#5

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


#7

Hi,

May I ask a question?


#8

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.