[英]“Fatal: too many params” when calling bash command from python, no error using same command directly in git bash
Expanding on a previously working function, I ran into a problem with the $(echo -e"...")-part, subprocess.call returns "fatal: too many params". 在扩展以前的工作功能时,我遇到了$(echo -e“ ...”)-部分subprocess.call返回“致命:太多参数”的问题。
If i copy the printed bashCmd and paste it directly in Git Bash, I end up with the expected result (new tag created with heading, and some formatted presentation of the "body" of the tag; "new functions: ... \\n bugfixes: ...\\n" etc. 如果我复制打印的bashCmd并将其直接粘贴到Git Bash中,则会得到预期的结果(带有标题的新标签以及该标签“ body”的某些格式表示;“新功能:... \\ n错误修正:... \\ n“等。
The printed bashCmd string passed as argument to subprocess.call: git tag -a v1.4.9 -m "new tag description" -m"$(echo -e "==New Features==\\n no new features\\n but feature 1\\n and feature 2\\n==Bugfixes==\\n fixed whitespace\\n hopefully it works\\n==Known Issues==\\n No Known Issues Reported.\\n")"
打印的bashCmd字符串作为参数传递给
git tag -a v1.4.9 -m "new tag description" -m"$(echo -e "==New Features==\\n no new features\\n but feature 1\\n and feature 2\\n==Bugfixes==\\n fixed whitespace\\n hopefully it works\\n==Known Issues==\\n No Known Issues Reported.\\n")"
bashCmd = 'git tag -a v' + str(major) + '.' + str(minor) + '.' + str(bugfix) +' -m'+ ''' "''' + heading + '''" '''+'-m'+ '''"$(echo -e'''+ ''' "''' +body+'''"''' ''')"'''
subprocess.call(bashCmd, shell=True)
print(bashCmd)
There is no reason for using the shell here. 这里没有理由使用外壳。 Use the list form for the first argument to
call
. 使用列表形式将第一个参数
call
。 Note this will require you to modify body
, but that will make it simpler . 请注意,这将需要您修改
body
,但这将使其更简单 。
body = """\
==New Features==
still not working
==Bugfixes==
0 bugs fixed
==Known Issues==
infinite amounts of bugs left"""
commit_msg = "heading\n\n" + body
version_str = '.'.join(['v', str(major), str(minor), str(bugfix)]),
git_cmd = [
'git',
'tag',
'-a',
version_str,
'-m',
commit_msg
]
subprocess.call(git_cmd)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.