更新时间:2022-12-16 21:37:02
当命令是 shell 内置时,在调用中添加 shell=True
.
When the command is a shell built-in, add a shell=True
to the call.
例如对于 dir
,您可以输入:
E.g. for dir
you would type:
import subprocess
subprocess.call('dir', shell=True)
引用文档:
在 Windows 上您唯一需要指定 shell=True
的时候是当您希望执行的命令内置到 shell 中时(例如 dir 或 copy).您不需要 shell=True
来运行批处理文件或基于控制台的可执行文件.
The only time you need to specify
shell=True
on Windows is when the command you wish to execute is built into the shell (e.g. dir or copy). You do not needshell=True
to run a batch file or console-based executable.