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!
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)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.