0

I have a python script that displays info about USB ports, which can be used to turn ports on/off. I want to run it from PHP.

I tried the following code without any options specified (which just displays info) and it worked:

$output = exec('python /home/ratta/usb_control.py');
echo  $output;

I then tried adding the necessary options but it doesn't turn the USB port off as it should:

$output = exec('python /home/ratta/usb_control.py --hub 001:011 --port 3 --power 0');
echo  $output;

Any ideas anyone? The script runs fine when running it manually without PHP.

Thanks

  • I think I've found the problem - the python script needs to be run as sudo, which isn't happening from php. How can I run the python script as sudo using php? – user2878409 Jul 17 '14 at 20:32
  • Since apparently you've dealt with the problem, see http://stackoverflow.com/questions/3173201/sudo-in-php-exec regarding the question in comment. – rr- Oct 21 '14 at 12:43

0 Answers0