可能重复:
从PHP调用Python并获取返回代码
可能是一个非常愚蠢的问题我有一个python模块让我们说hi.py有以下内容
print "hi"
Run Code Online (Sandbox Code Playgroud)
现在我想从php执行这个文件
<?php
#code here
?>
Run Code Online (Sandbox Code Playgroud)
那么如何从php调用该python文件.谢谢
使用exec函数调用Python.
例:
$output = array();
exec("python hi.py", $output);
var_dump( $output);
Run Code Online (Sandbox Code Playgroud)
还有其他命令用于在运行PHP的机器上执行命令,请参阅文档.