在Python中逃脱

0 python git

这种情况的正确代码是什么:

p = subprocess.Popen(["git", "log" , "-1",  "--pretty=format:\'%s %n%n%b\'", hash], 
  stdout=subprocess.PIPE)
out, err = p.communicate()
print out
message += '\n' + out
Run Code Online (Sandbox Code Playgroud)

我总是得到这个错误:

fatal: ambiguous argument '': unknown revision or path not in the working tree.
output: Use '--' to separate paths from revisions
Run Code Online (Sandbox Code Playgroud)

而我在工作树上.

Sve*_*ach 6

由于shell不解析调用,因此根本不需要引号:

p = subprocess.Popen(
    ["git", "log" , "-1",  "--pretty=format:%s %n%n%b", hash],
    stdout=subprocess.PIPE)
Run Code Online (Sandbox Code Playgroud)