我正在编写一个 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
>>>
直接运行:
$ pwd
/Users/aapa/Projects/supertext
$ git show c9a89aa:supertext/src/com/stxt/supercenter/rest/api/bootstrap/BootstrapDTO.java
package com.stxt.supercenter.rest.api.bootstrap;
import com.google.common.collect.Maps;
import com.stxt.base.rolepermission.enums.Role;
import com.stxt.superbase.profile.agent.bean.Agent;
import com.stxt.supercenter.rest.api.profile.agnet.AgentDTO;
import java.util.Arrays;
import java.util.Map;
.
.
.
有一点要指出风格的git show
输出,vi
即不是直接打印完整的文件,而是打印文件的一部分以覆盖完整的碎石,:
最后用 a 打印下一行或退出。
为什么我在使用时出现错误check_output
?