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")
精彩评论