我正在编写一个python脚本,其中我必须从脚本中读取git show
命令的输出。我决定使用python的subprocess.check_output
函数。在
但是它给了我No such file or directory
错误。在
从python运行:
>>> import subprocess
>>> subprocess.check_output(['pwd'])
'/Users/aapa/Projects/supertext\n'
>>> subprocess.check_output(['git show', 'c9a89aa:supertext/src/com/stxt/supercenter/rest/api/bootstrap/BootstrapDTO.java'])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 566, in check_output
process = Popen(stdout=PIPE, *popenargs, **kwargs)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 709, in __init__
errread, errwrite)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 1326, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory
>>>
直接运行:
^{pr2}$有一点需要指出的是git show
以vi
样式输出,即不是直接打印完整的文件,而是打印文件的一部分,以覆盖完整的屏幕,在最后用:
来打印下一行或退出。在
为什么我在使用check_output
时出错?在
试试这个:
否则,代码将尝试执行一个字面上包含空格(“
git show
”)的命令,而不是以show
作为第一个参数的git
命令。在相关问题 更多 >
编程相关推荐