系统找不到指定的文件 python 子进程
我正在尝试在Python中运行一个简单的命令:
from subprocess import *
check_output("ls")
当我运行这个命令时,它出现了
Error:
WindowsError: [Error 2] The system cannot find the file specified
1 个回答
3
ls
这个命令在Windows系统上是不存在的;而 dir
是可以用的。此外,你可能需要加上 shell=True
,因为这个命令是内置在 cmd.exe
里的。
如果你不是在做测试,只是想获取一个文件夹里的内容,可以使用 os.listdir
来实现。