php shell_exec无法正常工作

时间:2014-09-24 13:47:14

标签: php shell

以下代码在收到reboot命令后工作并重新启动系统,但是由于某些奇怪的原因,它不会执行此shell命令sudo i2cset -y 1 0x70 0x00 0xa5,请提供任何帮助。

<?php

  function sys_cmd($cmd) {
    if(strncmp($cmd, "reboot", strlen("reboot")) == 0) 
    {
      shell_exec('sudo shutdown -r now');
    } 
    else if(strncmp($cmd, "lighton", strlen("lighton")) == 0) 
    {
      shell_exec('sudo i2cset -y 1 0x70 0x00 0xa5');
    }
    else if(strncmp($cmd, "lightoff", strlen("lightoff")) == 0) 
    {
      shell_exec('sudo i2cset -y 1 0x70 0x00 0x00');
    }
    else {
      // unknown
    }
  }


  if(isset($_GET['cmd'])) {
    $cmd=$_GET['cmd'];
    sys_cmd($cmd);
  }

?>

0 个答案:

没有答案
相关问题