"Fatal: too many params" 从 python 调用 bash 命令时,直接在 git bash 中使用相同的命令没有错误
"Fatal: too many params" when calling bash command from python, no error using same command directly in git bash
扩展以前的工作功能,我 运行 遇到 $(echo -e"...") 部分的问题,subprocess.call returns "fatal: too many params".
如果我复制打印的 bashCmd 并将其直接粘贴到 Git Bash,我最终会得到预期的结果(使用标题创建的新标签,以及 "body" 标签;"new functions: ... \n bugfixes: ...\n" 等
打印的 bashCmd 字符串作为参数传递给 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 v' + str(major) + '.' + str(minor) + '.' + str(bugfix) +' -m'+ ''' "''' + heading + '''" '''+'-m'+ '''"$(echo -e'''+ ''' "''' +body+'''"''' ''')"'''
subprocess.call(bashCmd, shell=True)
print(bashCmd)
这里没有理由使用shell。 call
的第一个参数使用列表形式。请注意,这将要求您修改 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)
扩展以前的工作功能,我 运行 遇到 $(echo -e"...") 部分的问题,subprocess.call returns "fatal: too many params".
如果我复制打印的 bashCmd 并将其直接粘贴到 Git Bash,我最终会得到预期的结果(使用标题创建的新标签,以及 "body" 标签;"new functions: ... \n bugfixes: ...\n" 等
打印的 bashCmd 字符串作为参数传递给 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 v' + str(major) + '.' + str(minor) + '.' + str(bugfix) +' -m'+ ''' "''' + heading + '''" '''+'-m'+ '''"$(echo -e'''+ ''' "''' +body+'''"''' ''')"'''
subprocess.call(bashCmd, shell=True)
print(bashCmd)
这里没有理由使用shell。 call
的第一个参数使用列表形式。请注意,这将要求您修改 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)