Reputation: 53
I am trying to run a simple command in python:
from subprocess import *
check_output("ls")
When I run this it raises
Error:
WindowsError: [Error 2] The system cannot find the file specified
Upvotes: 2
Views: 1376
Reputation: 129011
ls
doesn’t exist on Windows; dir
does. Furthermore, you may need to pass shell=True
, since it’s built in to cmd.exe
.
If it’s not a test and you just want to get the contents of a directory, use os.listdir
instead.
Upvotes: 3