通过IIS运行时无法从Popen获取输出

时间:2013-07-18 11:47:08

标签: python iis cgi subprocess

我在Windows Server 2008上使用以下python脚本:

import cgitb
import subprocess

cgitb.enable()
print "Content-Type: text/plain;charset=utf-8"
print

cmd = "git tag"
process = subprocess.Popen(cmd.split(), shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
git_output = process.communicate()[0]
print "git output = %s" % git_output

事实上,有一些git标签。通过shell运行此脚本非常有效。但是,当通过IIS(7)运行时,输出似乎是空的。

我尝试将Popen输出定向到文件而不是PIPE。再次,从命令行运行时工作,在通过IIS运行时不起作用。

有什么想法吗?

编辑:

按照@ Wooble的建议,我从通话中删除[0]以查看git错误,并且确实发现神秘错误“'git'未被识别为内部或外部命令,可操作程序或批处理文件。 “当然git安装在系统上,正如我所说,当直接通过命令行运行脚本时。

无济于事,我试过了:

  1. 设置命令以使用git可执行文件的完整路径
  2. 将git可执行文件目录的完整路径添加到python的sys.path
  3. 将实际的git可执行文件复制到工作目录 - 这删除了“git not recognized”错误但仍然产生了空结果!
  4. 请帮助!!

1 个答案:

答案 0 :(得分:0)

我不知道为什么从IIS运行时路径是偏的(解释欢迎!),但添加这个最终解决了问题:

git_path = "C:\\Program Files (x86)\\Git\\bin\\"
os.environ["PATH"} += git_path + ';'
相关问题