php call python - Linux
By Margaret
at 2021-04-29T00:16
at 2021-04-29T00:16
Table of Contents
各位大大好
想請教一下
如果我目前想在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, 不知是否有其他相關的作法 感謝
--
Tags:
Linux
All Comments
By Jessica
at 2021-04-29T09:53
at 2021-04-29T09:53
By Ula
at 2021-04-29T19:30
at 2021-04-29T19:30
By Tracy
at 2021-04-30T05:07
at 2021-04-30T05:07
By Ethan
at 2021-04-30T14:44
at 2021-04-30T14:44
By Sarah
at 2021-05-01T00:22
at 2021-05-01T00:22
Related Posts
Gnuplot 繪圖 terminal pdfcairo
By Daph Bay
at 2021-04-28T18:33
at 2021-04-28T18:33
Container內 cin疑問
By Lydia
at 2021-04-25T23:03
at 2021-04-25T23:03
請問現在 Linux 繁中注音輸入法是不是一灘死水?
By Hardy
at 2021-04-25T15:22
at 2021-04-25T15:22
Gnuplot (繪圖)
By Una
at 2021-04-22T21:31
at 2021-04-22T21:31
可在已安裝系統分區的硬碟上作軟raid嗎
By Franklin
at 2021-04-21T21:38
at 2021-04-21T21:38