【发布时间】:2021-04-19 22:08:43
【问题描述】:
似乎 python subprocess.run 在最后一个参数后附加了一个双引号:
Python 3.9.4 (tags/v3.9.4:1f2e308, Apr 6 2021, 13:40:21) [MSC v.1928 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import subprocess
>>> args = ['cmd', '/c', 'echo', 'hello']
>>> result = subprocess.run(args, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
>>> result.stdout
b'hello"\r\n'
>>> stdout = str(result.stdout, "utf-8").strip()
>>> stdout
'hello"'
我使用的是 Windows 20H2 19042.928。
我在上面做错了什么?
【问题讨论】:
-
好吧,看来我需要在 shell=True 和使用 cmd 之间进行选择。但我还是不明白双引号。
标签: python windows subprocess double-quotes