【发布时间】:2021-08-19 02:54:54
【问题描述】:
我在努力
git status *> test.txt
这在 powershell 中运行良好,但如果我使用 python 执行此操作 -
os.system('git status'+' *> '+log_path+'\git_output.txt')
fatal: '*' 似乎不是 git 存储库 致命:无法从远程存储库读取。
os.system('git status'+' 2> '+log_path+'\git_output.txt')
顺便说一句,这行得通!但我想要文件中的各种输出!
最好的方法是什么?
【问题讨论】:
-
Powershell 可能会插入
*。 -
请注意,Git 本身有些不寻常,因为它经常将“正常”输出写入其标准错误输出(C 代码中的文件描述符 2,Python 中的
os.stderr)。作为mklelement0 notes in a comment,这里的问题是os.system没有使用 PowerShell。考虑使用subprocess.Popen来捕获标准输出和标准错误。 -
@dan1st 但是有什么选项可以使用 *> 强制指定它的确切意图吗?
-
你可以在
powershell中显式运行命令。 -
也有相关的,有更多的链接以获得更多的背景阅读:stackoverflow.com/q/34186035/1256452
标签: python git powershell