簡體   English   中英

從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返回“致命:太多參數”的問題。

如果我復制打印的bashCmd並將其直接粘貼到Git Bash中,則會得到預期的結果(帶有標題的新標簽以及該標簽“ body”的某些格式表示;“新功能:... \\ n錯誤修正:... \\ 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)

這里沒有理由使用外殼。 使用列表形式將第一個參數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)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM