【发布时间】:2014-04-18 02:34:19
【问题描述】:
这个 sn-p 代码适用于我可以访问的大多数 Unix(Linux、Solaris、AIX)以及 Windows 7/Server 2008 R2 以及我用来获取 git log 输出的更高版本:
from subprocess import Popen, PIPE
import platform
cmd = ["git", "--no-pager"]
if platform.system() == "Windows":
cmd.append("--work-tree=/path/to/working/copy")
cmd.extend(["log", "--pretty=format:\"%cd %h\"", "--date=short", "--", "/path/to/working/copy/filename/to/check"])
proc = Popen(cmd, stdout=PIPE, stderr=PIPE)
proc.wait()
f = proc.stdout
some_stuff = f.read()
f.close()
但是,在使用 msysgit 的 Windows XP 上,我没有得到 some_stuff 变量的任何值,这很奇怪,因为在 Windows 上运行生成的命令可以在命令行上运行。
关于我应该在这里做什么的任何提示?
【问题讨论】:
-
这可能是 XP 上的 msysgit 版本的问题,你用 cygwin 的 git 试过了吗?
-
我倾向于尽可能避免使用 Cygwin,因为这需要对我正在维护的构建系统进行过多的重组(MSBuild + GNU Make + 批处理文件的奇怪组合,现在在混合)。
-
通过在 Windows 上不指定
--work-tree选项、在 Windows 上使用 git.cmd 而不是 git.exe 以及确保要检查的文件名具有其驱动器号来解决此问题大写。
标签: python windows git windows-xp