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