I have a python script and I wanna know if the request is from web or from command line. How can I do this?
Thanks
I have a python script and I wanna know if the request is from web or from command line. How can I do this?
Thanks
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")