Running a Python script from PHP

后端 未结 9 2017
鱼传尺愫
鱼传尺愫 2020-11-22 00:57

I\'m trying to run a Python script from PHP using the following command:

exec(\'/usr/bin/python2.7 /srv/http/assets/py/switch.py arg1 arg2\');

H

9条回答
  •  盖世英雄少女心
    2020-11-22 01:26

    This is so trivial, but just wanted to help anyone who already followed along Alejandro's suggestion but encountered this error:

    sh: blabla.py: command not found

    If anyone encountered that error, then a little change needs to be made to the php file by Alejandro:

    $command = escapeshellcmd('python blabla.py');
    

提交回复
热议问题