Revision 362fbca0-fe84-436d-b9e7-93f4fd814768 - Stack Overflow
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";
}
?>
[1]: http://php.net/manual/en/function.shell-exec.php