[問題] php call python
各位大大好
想請教一下
如果我目前想在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, 不知是否有其他相關的作法 感謝
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 223.140.62.217 (臺灣)
※ 文章網址: https://www.ptt.cc/bbs/Python/M.1619645456.A.A0D.html
→
04/29 09:22,
3年前
, 1F
04/29 09:22, 1F
推
04/29 23:27,
3年前
, 2F
04/29 23:27, 2F
→
04/30 09:56,
3年前
, 3F
04/30 09:56, 3F
→
04/30 11:26,
3年前
, 4F
04/30 11:26, 4F
推
04/30 15:21,
3年前
, 5F
04/30 15:21, 5F
→
04/30 15:21,
3年前
, 6F
04/30 15:21, 6F
→
04/30 16:11,
3年前
, 7F
04/30 16:11, 7F
→
05/02 10:24,
3年前
, 8F
05/02 10:24, 8F
→
05/02 10:24,
3年前
, 9F
05/02 10:24, 9F
→
05/02 10:24,
3年前
, 10F
05/02 10:24, 10F