shell_exec — Execute command via shell and return the complete output as a string . [reference][1]reference
<?php
if(isset($_POST['switch'])){
$c=escapeshellcmd("sudo python /home/pi/Desktop/test.py");
$res=shell_exec($c);
echo $res; // returns result to display
}
?>
in your script,output is not printed that may seem to not working
<?php
if(isset($_POST['switch'])){
$s=exec("sudo python /home/pi/Desktop/test.py");
echo "$s";
}
?>
EDIT:
add full path of interpreter in the first line of python script . if you have installed more than one python version
$s=exec("sudo -u /home/pi/Desktop/test.py");this gives permission to python file
first of all make python file executable with
chmod +x /path/to/python-script.py[1]: http://php.net/manual/en/function.shell-exec.php
EDIT:
from this post
You can't use sudo from a PHP script. Apache is running from an user (www-data generaly), so edit this file : /etc/sudoers
Then add this line :
www-data ALL=(ALL) NOPASSWD:ALL
Care ! this will authorize all functions to be called by a PHP script, you can adapt changing "ALL" by your script or Python command.
Then precise your user in your exec command :
<?php
exec('sudo -u www-data python /usr/lib/cgi-bin/script.py')
shell_exec — Execute command via shell and return the complete output as a string . [reference][1]
<?php
if(isset($_POST['switch'])){
$c=escapeshellcmd("sudo python /home/pi/Desktop/test.py");
$res=shell_exec($c);
echo $res; // returns result to display
}
?>
in your script,output is not printed that may seem to not working
<?php
if(isset($_POST['switch'])){
$s=exec("sudo python /home/pi/Desktop/test.py");
echo "$s";
}
?>
EDIT:
add full path of interpreter in the first line of python script . if you have installed more than one python version
$s=exec("sudo -u /home/pi/Desktop/test.py");this gives permission to python file
first of all make python file executable with
chmod +x /path/to/python-script.py[1]: http://php.net/manual/en/function.shell-exec.php
shell_exec — Execute command via shell and return the complete output as a string . reference
<?php
if(isset($_POST['switch'])){
$c=escapeshellcmd("sudo python /home/pi/Desktop/test.py");
$res=shell_exec($c);
echo $res; // returns result to display
}
?>
in your script,output is not printed that may seem to not working
<?php
if(isset($_POST['switch'])){
$s=exec("sudo python /home/pi/Desktop/test.py");
echo "$s";
}
?>
add full path of interpreter in the first line of python script . if you have installed more than one python version
$s=exec("sudo -u /home/pi/Desktop/test.py");this gives permission to python file
first of all make python file executable with
chmod +x /path/to/python-script.py
EDIT:
from this post
You can't use sudo from a PHP script. Apache is running from an user (www-data generaly), so edit this file : /etc/sudoers
Then add this line :
www-data ALL=(ALL) NOPASSWD:ALL
Care ! this will authorize all functions to be called by a PHP script, you can adapt changing "ALL" by your script or Python command.
Then precise your user in your exec command :
<?php
exec('sudo -u www-data python /usr/lib/cgi-bin/script.py')
shell_exec — Execute command via shell and return the complete output as a string . reference [reference][1]
<?php
if(isset($_POST['switch'])){
$c=escapeshellcmd("sudo python /home/pi/Desktop/test.py");
$res=shell_exec($c);
echo $res; // returns result to display
}
?>
in your script,output is not printed that may seem to not working
<?php
if(isset($_POST['switch'])){
$s=exec("sudo python /home/pi/Desktop/test.py");
echo "$s";
}
?>
EDIT:
add full path of interpreter in the first line of python script . if you have installed more than one python version
$s=exec("sudo -u /home/pi/Desktop/test.py");this gives permission to python file
first of all make python file executable with
chmod +x /path/to/python-script.py[1]: http://php.net/manual/en/function.shell-exec.php
shell_exec — Execute command via shell and return the complete output as a string . reference
<?php
if(isset($_POST['switch'])){
$c=escapeshellcmd("sudo python /home/pi/Desktop/test.py");
$res=shell_exec($c);
echo $res; // returns result to display
}
?>
in your script,output is not printed that may seem to not working
<?php
if(isset($_POST['switch'])){
$s=exec("sudo python /home/pi/Desktop/test.py");
echo "$s";
}
?>
shell_exec — Execute command via shell and return the complete output as a string . [reference][1]
<?php
if(isset($_POST['switch'])){
$c=escapeshellcmd("sudo python /home/pi/Desktop/test.py");
$res=shell_exec($c);
echo $res; // returns result to display
}
?>
in your script,output is not printed that may seem to not working
<?php
if(isset($_POST['switch'])){
$s=exec("sudo python /home/pi/Desktop/test.py");
echo "$s";
}
?>
EDIT:
add full path of interpreter in the first line of python script . if you have installed more than one python version
$s=exec("sudo -u /home/pi/Desktop/test.py");this gives permission to python file
first of all make python file executable with
chmod +x /path/to/python-script.py[1]: http://php.net/manual/en/function.shell-exec.php
you can do like thisshell_exec — Execute command via shell and return the complete output as a string . reference
<?php
if(isset($_POST['switch'])){
$c=escapeshellcmd("sudo python /home/pi/Desktop/test.py");
$res=shell_exec($c);
echo $res; // returns result to display
}
?>
in your script,output is not printed that may seem to not working
<?php
if(isset($_POST['switch'])){
$s=exec("sudo python /home/pi/Desktop/test.py");
echo "$s";
}
?>
output is not printed that may seem to not working
you can do like this
<?php
if(isset($_POST['switch'])){
$c=escapeshellcmd("sudo python /home/pi/Desktop/test.py");
$res=shell_exec($c);
echo $res; // returns result to display
}
?>
in your script
<?php
if(isset($_POST['switch'])){
$s=exec("sudo python /home/pi/Desktop/test.py");
echo "$s";
}
?>
output is not printed that may seem to not working
shell_exec — Execute command via shell and return the complete output as a string . reference
<?php
if(isset($_POST['switch'])){
$c=escapeshellcmd("sudo python /home/pi/Desktop/test.py");
$res=shell_exec($c);
echo $res; // returns result to display
}
?>
in your script,output is not printed that may seem to not working
<?php
if(isset($_POST['switch'])){
$s=exec("sudo python /home/pi/Desktop/test.py");
echo "$s";
}
?>