[問題] php call python

看板Linux作者 (~(⊙o⊙)~)時間3年前 (2021/04/29 00:16), 編輯推噓1(106)
留言7則, 4人參與, 3年前最新討論串1/1
各位大大好 想請教一下 如果我目前想在linux 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/Linux/M.1619626577.A.EB0.html

04/29 00:50, 3年前 , 1F
考慮看看用python另外跑個server,用php發request給
04/29 00:50, 1F

04/29 00:50, 3年前 , 2F
04/29 00:50, 2F

04/29 01:31, 3年前 , 3F
權限問題?
04/29 01:31, 3F

04/29 09:37, 3年前 , 4F
我猜大概是 open_basedir 設定, 是說用 linux 還用 ap
04/29 09:37, 4F

04/29 09:37, 3年前 , 5F
pserv 只是自找麻煩
04/29 09:37, 5F

04/29 20:54, 3年前 , 6F
先用whereis python3看一下路徑 打完整路徑上去再試試看
04/29 20:54, 6F

05/03 21:13, 3年前 , 7F
乾 which啦打錯
05/03 21:13, 7F
文章代碼(AID): #1WYOfHwm (Linux)