donglang6656 2018-03-20 22:39
浏览 75


I want to execute a python script,, from a php function.

#!/usr/bin/env python
import random

def test() :
   print("test success")

if __name__ == '__main__':

I can successfully execute it using php command line:

php -r '$message = exec("python3 ~/../scripts/"); print_r($message);' 

I've added the following to my php code:

$message = exec("python3 ~/../scripts/", $output, $return_val); 

When I execute it, nothing is output (no errors in devtools). When I print the variables, $output and $message are empty and $return_val is 2 (misuse of shell builtins according to Bash documentation).

I know exec() is allowed after adding the following into the same function:

if (exec('echo TEST') == 'TEST')
      echo 'exec works!';

What could be causing this error? How can I execute the python script with php?

  • 写回答

1条回答 默认 最新


      相关推荐 更多相似问题


      • ¥15 在matlab中如何进行三个参数的离散傅里叶逆变换(idft)
      • ¥15 遇到问题了,求解答!
      • ¥15 请问coppliasim eduUR5视觉抓取怎么实现仿真,
      • ¥30 JavaWeb实验(购物平台)
      • ¥15 八路抢答器倒计时设计时显示器不输出,只能显示0
      • ¥15 用C语言随机生成一个迷宫
      • ¥15 超多因素的正交方案设计
      • ¥15 Scratch~汽车小游戏
      • ¥30 OSGB转换为3dtiles
      • ¥25 用于Audio的芯片中“Audio Interface”和“Mode Control”是什么?