The python sh docs say:蟒蛇SH库,用连字符/破折号命令
对于有破折号在其名称中的命令,例如在/ usr/bin中/谷歌铬,代替破折号下划线:
我试图运行命令
git rev-parse --abbrev-ref HEAD
当我尝试运行命令,混帐返回我有错误的命令是错误的。任何方式来解决这个问题?
>>> from sh import git
>>> git.rev_parse('--abbrev-ref', 'HEAD')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Python/2.7/site-packages/sh.py", line 769, in __call__
return RunningCommand(cmd, call_args, stdin, stdout, stderr)
File "/Library/Python/2.7/site-packages/sh.py", line 330, in __init__
self.wait()
File "/Library/Python/2.7/site-packages/sh.py", line 334, in wait
self._handle_exit_code(self.process.wait())
File "/Library/Python/2.7/site-packages/sh.py", line 348, in _handle_exit_code
self.process.stderr
sh.ErrorReturnCode_1:
RAN: '/usr/bin/git rev_parse --abbrev-ref HEAD'
STDOUT:
STDERR:
git: 'rev_parse' is not a git command. See 'git --help'.
Did you mean this?
rev-parse
>>>
个人而言,我认为这是'sh'模块为什么是黑客集合的一个例子,与内置'subprocess'模块的简单行为相比。是的,他们有时候很可爱,并且可以用于编码 - 但如果人们关心正确性,行为应该尽可能明确和清楚地指定。 – 2014-12-05 17:18:50