duanjia7912 2015-06-29 17:00
浏览 21

用PHP执行Python

I try to execute this PHP command :

 $result = exec("sudo python /home/pi/test.py",$output, $ret);
 var_dump($result);
 echo "<br>";
 var_dump($output);
 echo "<br>";
 var_dump($ret);

This command works perfectly on a Linux Terminal but with the PHP it doesn't work.

Here the result on the PHP page :

string(0)
array(0) { }
int(9)

I verified the process with ps -ef, nothing appears.

  • 写回答

1条回答 默认 最新

  • duanliao2310 2015-07-01 15:06
    关注

    It might be help someone with the same problem. I managed later to execute a Python script with this PHP code :

    $command = escapeshellcmd('sudo /home/pi/test.py');
    $output = shell_exec($command);
    echo $output;
    

    For the moment, I never succeed to execute this in background. I try those solutions :

    $command = escapeshellcmd("sudo /home/pi/test.py >/dev/null &");
    
    $command = escapeshellcmd("sudo /home/pi/test.py &");
    

    My PHP page wait also the end of the process, but i don't want to.

    评论

报告相同问题?

悬赏问题

  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法