且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Windows 在 subprocess.call() 上找不到文件

更新时间: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 中时(例如 dircopy).您不需要 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 need shell=True to run a batch file or console-based executable.