【问题标题】:Distinguish from command line and CGI in python区分python中的命令行和CGI
【发布时间】:2012-08-04 06:23:18
【问题描述】:

是否可以区分我的 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?

【问题讨论】:

    标签: python cgi


    【解决方案1】:

    Perl answer 也适用于 Python;检查GATEWAY_INTERFACEenvironment variable

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-12-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-22
      • 2012-05-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多