简体   繁体   中英

“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".

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.

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 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 . Note this will require you to modify body , but that will make it simpler .

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM