扩展之前的工作函数,我遇到了 $(echo -e"...") 部分的问题,subprocess.call 返回“致命:参数太多”。
如果我复制打印的 bashCmd 并将其直接粘贴到 Git Bash 中,我最终会得到预期的结果(使用标题创建的新标签,以及标签“主体”的一些格式化表示;“新功能:.. .\n 错误修复:...\n"等。
打印的 bashCmd 字符串作为参数传递给 subprocess.call:
git tag -a v1.4.9 -m "新标签描述"-m"$(echo -e "==新功能==\n没有新功能\n但功能1\n和功能2\n= =错误修复==\n修复了空格\n希望它能工作\n==已知问题==\n没有报告已知问题。\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)
关于python - "Fatal: too many params"从 python 调用 bash 命令时,直接在 git bash 中使用相同命令没有错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54723271/