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



我在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"错误,但仍然产生了空结果

请帮忙!!

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

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

最新更新