为什么 glob * 通配符在 python subprocess.call 中不起作用?

Why isn't glob * wildcard working in python subprocess.call?

我想在 subprocess.call 函数中使用这样的 glob 模式:

>>> subprocess.call(["ls", "output*"])
ls: cannot access output*: No such file or directory
2
>>> subprocess.call(["ls", "output\*"])
ls: cannot access output\*: No such file or directory
2

但不能在上面的文件名 "output" 后使用 glob(*) 模式。

Globbing(扩展 *)是您 shell 的一个功能。您需要添加 shell=True 参数以通过 shell 解释器执行命令。

subprocess.call("ls output*", shell=True)