gpt4 book ai didi

Python 子进程在 Windows 上不传递大括号作为参数

转载 作者:行者123 更新时间:2023-12-01 05:27:07 25 4
gpt4 key购买 nike

在 Windows 命令行中,以下行为与预期完全一致:

C:\> c:\cygwin\bin\printf "<%s>\n" "{foo}"
{foo}

但是,从 native win32 Python 实例内部,大括号被删除:

>>> subprocess.Popen(['c:\\cygwin\\bin\\printf', '<%s>\n', '{foo}'],
... stdout=subprocess.PIPE).communicate()[0].rstrip('\n')
'foo'

这是怎么回事?

最佳答案

您应该能够使用pipes.quote()来解决此问题: http://docs.python.org/2/library/pipes.html#pipes.quote

或者,如果您使用的是 python3,请查看 shlex.quotes(): http://docs.python.org/2/library/shlex.html#module-shlex

关于Python 子进程在 Windows 上不传递大括号作为参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21106433/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com