[请问] php call python

楼主: lccf   2021-04-28 20:16:07
各位大大好
想请教一下
如果我目前想在appserv环境下 写一只PHP 去执行python
有参考相关的做法
PHP端
test.php
<?php
$command = escapeshellcmd('python3 /usr/custom/test.py');
$output = shell_exec($command);
echo $output;
?>
Python端: test.py
fp = open("filename.txt", "a")
# 写入 This is a testing! 到档案
fp.write("This is a testing!")
# 关闭档案
fp.close()
如果用以下执行时 http://127.0.0.1/test.php
会无法正常产生filename.txt
他会直接略过整只python, 不知是否有其他相关的作法 感谢

Links booklink

Contact Us: admin [ a t ] ucptt.com