-2

I was doing an exersize with the following task: Write a python program to call an external command in Python.

As I could not solve it by my own I looked up the solution:

from subprocess import call
call(["ls", "-l"])

But the solution threw an Error: FileNotFoundError: [WinError 2]

I also tried adding shell=True and for example leaving out the brackets like following:

subprocess.call('ls -l', shell=True)

In this case it tells me that the command "ls" could not be found.

I am working on windows 10,Python 3.8.2 32 bit

I am kind of lost and would be glad if someone could help.

Thank you!

Almog-at-Nailo
  • 1,152
  • 1
  • 4
  • 20

1 Answers1

2

ls is not a valid Windows CMD command. For learning purpose, you may try CD for printing current directory, ie

import subprocess
subprocess.call(['CD'], shell=True)
hellojoshhhy
  • 855
  • 2
  • 15
  • 32