看板 PHP 關於我們 聯絡資訊
各位大大好 想請教一下 如果我目前想在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/PHP/M.1619611923.A.F30.html
jonyig: 可能沒有權限產檔案 04/29 00:33
guardlan: 執行環境變數不一樣 python3 改用絕對路徑試試 04/30 00:43
planetoid2: 先確認 PHP 有權限寫入檔案到 /usr/custom/ 04/30 12:32
sum90707: 先確認是整隻沒有跑還是中間有壞 04/12 13:57