开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜