日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

python怎么启动服务器_如何通过cgi启动服务器端python程序?

發(fā)布時間:2025/3/19 47 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python怎么启动服务器_如何通过cgi启动服务器端python程序? 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

問題在于:subprocess.call("python /home/pi/test.py")

它從名為“python/home/pi”的可執(zhí)行文件中查看您的PATH/測試.py“-所有一個程序,名稱中有空格。您需要傳遞一個參數(shù)列表,而不是命令行。如the docs解釋:args is required for all calls and should be a string, or a sequence of program arguments. Providing a sequence of arguments is generally preferred, as it allows the module to take care of any required escaping and quoting of arguments (e.g. to permit spaces in file names). If passing a single string, either shell must be True (see below) or else the string must simply name the program to be executed without specifying any arguments.

所以,這樣做:

^{pr2}$

它將查找名為“python”的可執(zhí)行文件,并使用“/home/pi”運行它/測試.py”作為它的第一個參數(shù)(并且以“python”作為其第零個參數(shù)),這就是您想要的。在

它可能仍然不起作用-python必須位于您的特殊Apache用戶的路徑上,通過一個可訪問的路徑,并且是可執(zhí)行的。通常通過sys.executable或{}或任何合適的方法比較好。在

同時,如果您不直接調(diào)用call并忽略結果,那么調(diào)試它會更容易(比如在并非完全不可能的情況下)。例如:ret = call(["python", "/home/pi/test.py"])

if ret:

print "Running test.py returned", ret

……或者try:

check_call(["python", "/home/pi/test.py"])

except Exception as e:

print "Tried to run test.py, got back", repr(e)

或者…你真的希望它的輸出直接傳遞到CGI嗎?如果沒有,您可能需要捕獲它的輸出并對其執(zhí)行某些操作,例如:try:

output = check_output(["python", "/home/pi/test.py"])

except Exception as e:

print "Tried to run test.py, got back", repr(e)

else:

print "test.py said", output

總結

以上是生活随笔為你收集整理的python怎么启动服务器_如何通过cgi启动服务器端python程序?的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。