区别于python中的命令行和CGI

时间:2012-08-07 09:02:09

标签: python cgi

是否可以区分我的Python脚本是从Web服务器(作为CGI脚本)还是从命令行执行?

我看过只有PHP和Perl的回复:
What is the canonical way to determine commandline vs. http execution of a PHP script?
How can I determine if a script was called from the command line or as a cgi script?

1 个答案:

答案 0 :(得分:2)

Perl answer也适用于Python;检查GATEWAY_INTERFACE environment variable

import os
if 'GATEWAY_INTERFACE' in os.environ:
    print ('CGI')
else:
    print ('Not CGI. CLI?')
相关问题