PHP - Function exec, shell_exec and system do not work properly

Asked

Viewed 616 times

0

Running the example of documentation on the site works.

Examples:

echo exec('whoami');

$output = shell_exec('ls -l');
echo "<pre>$output</pre>";

My code does not differ so much from the examples described in the documentation, what I want to do is just run another application with the following command:

My code/example:

> $comando = "python3 caminho/arquivo.py";
> exec($comando);

And now folks!?

  • Do you want to run a Python or PHP file? Or do you have a PHP application that runs a Python file?

  • Yes, I have an application running in PHP that will run a python file. To be more exact the application will give the command execution in the terminal to run a python script. Which in my case the command is: python3 path/file.py

  • What’s the problem? I couldn’t understand it very well. What would be "not working properly?". If there is an error message or some unexpected behavior, edit your question and add more information

  • does not work correctly refers to the point of which for commands like: ls, mkdir, pwd. It works, but "python3 path/file.py" is a command just like any other and it doesn’t run/work.

  • check the permission in the directory and in the file you want php to run

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.