How do I know if a program is running from the command line or from the Internet?

I have a python script and I want to know if the request is from the Internet or from the command line. How can i do this?

+7
python command-line cgi
source share
1 answer

When launched, environment variables such as REQUEST_METHOD will be present as REQUEST_METHOD . If not, then you are not working in a CGI environment.

You can check it as follows:

 import os if os.getenv("REQUEST_METHOD"): print("running as CGI") else: print("not running as CGI") 
+9
source share

All Articles