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
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
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.
echo, but that’s even more likely to be a shell built-in. It needs shell=True because there’s no dir.exe (as far as I know); the functionality is built into cmd.exe, the shell.subprocess module as you were testing here. If you can express your problem more clearly, you can ask another question.