【发布时间】:2015-02-03 21:36:31
【问题描述】:
对于名称中包含短划线的命令,例如 /usr/bin/google-chrome,请将短划线替换为下划线:
我正在尝试运行命令
git rev-parse --abbrev-ref HEAD
当我尝试运行命令时,git 返回一个错误,我有错误的命令。有什么办法可以解决这个问题?
>>> 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模块的更简单行为相比。是的,它们有时是可爱的 hack,并且可以编写更简洁的代码——但如果人们关心正确性,行为应该尽可能明确和明确。