I have a script that I wrote that can either be used on the command line or as a CGI script, and need to determine how the script was called so I can output a content-type h
According to the CGI specification in RFC3875 (section 4.1.4.), the GATEWAY_INTERFACE environment variable would be the authoritative thing to check whether you are running in a CGI context:
4.1.4.
GATEWAY_INTERFACEThe
GATEWAY_INTERFACEvariable MUST be set to the dialect of CGI being used by the server to communicate with the script.