Reputation: 87
here is my code in control.php:-
<?php
$output = shell_exec("/var/www/script.py");
?>
why i cant run the shell_exec() command when i run the php script..? it should call the script.py and execute the py script.. but, when i run the control.php script..
note that i tried to run a normal program by using php where i tried to open gedit by using the command below:-
<?php exec('gedit');?>
the gedit is not executed..
anyone can help me?
Upvotes: 0
Views: 9977
Reputation: 87
the reason is because of the php doesnt have the permission to write/read the py script in desktop.. so, just change the directory of the py to the same directory as the php file then eveything runs smoothly..
Upvotes: 0
Reputation: 6138
You probably need to specify python
in shell_exec()
explicitly:
$output = shell_exec("/usr/bin/python /var/www/script.py")
or
$output = shell_exec("python /var/www/script.py")
and you need to ensure that your script.py
has a permission better than "-rwxrwxr-x"
as your php probably is executed by a different user.
Upvotes: 1
Reputation: 1285
Can you run "/var/www/script.py" in the BASH? if NOT, then check the script,make sure contain the following line:
#!/usr/bin/env python
then chmod +x script.py to make sure it is executable.
Upvotes: 1