从Fat中调用bash命令时“致命:太多params”,没有错误直接在git bash中使用相同的命令

问题描述 投票:1回答:1

扩展了以前工作的函数,我遇到了$(echo -e“...”)的问题 - 部分,subprocess.call返回“致命:太多的参数”。

如果我复制打印的bashCmd并将其直接粘贴到Git Bash中,我最终会得到预期的结果(用标题创建的新标签,以及标签“body”的一些格式化表示;“新功能:...... \ n错误修正:... \ 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)
python bash git subprocess git-bash
1个回答
2
投票

这里没有理由使用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)
© www.soinside.com 2019 - 2024. All rights reserved.