I have a Laravel app. It displays a simple view with some buttons. When a button is pressed it should call an api and access a function in my controller and execute a python script.
The problem is:
- If I run the app in local it works
- If I run the python script from command line it works
- If I run the app on my debian server it does not work
The script gets executed with exec
function (also tried shell_exec
with same result), but it doesn't return any output, doesn't throw errors or exceptions, and return code is always 1
.
exec('timeout 10 python3 ' . public_path('send_command.py') . ' -c ' . escapeshellarg($command) . ' -s ' . escapeshellarg($serial), $output, $result);
I also tried to build the command first, print it and then execute it: it gets printed fine (if I copy and paste that in command line it works) but the result is always the same.
Also tried this but to no avail.
N.B. Currently send_command.py
is inside public
folder because I noticed that it treats it as the current shell directory, but this doesn't work even if the script is in the project root or inside controllers folder.
Anyone has any idea of what is going on?
What's different between exec()
(or shell_exec()
) and the command line?