开发者

How can I discover if a program is running from command line or from web?

开发者 https://www.devze.com 2023-01-22 17:19 出处:网络
I have a python script and I wanna know if the request is from web o开发者_C百科r from command line. How can I do this?When run as a CGI, environment variables such as REQUEST_METHOD will be present.

I have a python script and I wanna know if the request is from web o开发者_C百科r from command line. How can I do this?


When run as a CGI, environment variables such as REQUEST_METHOD will be present. If not, then you're not running in a CGI environment.

You can check this like this:

import os
if os.getenv("REQUEST_METHOD"):
    print("running as CGI")
else:
    print("not running as CGI")
0

精彩评论

暂无评论...
验证码 换一张
取 消