I have a python script and I wanna know if the request is from web or from command line. How can I do this?
Open the terminal window on Linux. For remote Linux server use the ssh command for log in purpose. Type the ps aux to see all running process in Linux. Alternatively, you can issue the top command or htop command to view running process in Linux.
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")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With