user37970
user37970

Reputation: 53

system cannot find the specified file python subprocess

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

Answers (1)

icktoofay
icktoofay

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

Related Questions