The stack trace suggests you're using Windows as the operating system. ls not something that you will typically find on a Windows machine unless using something like CygWin.
Instead, try one of these options:
# use python's standard library function instead of invoking a subprocess
import os
os.listdir()
# invoke cmd and call the `dir` command
import subprocess
subprocess.run(["cmd", "/c", "dir"])
# invoke PowerShell and call the `ls` command, which is actually an alias for `Get-ChildItem`
import subprocess
subprocess.run(["powershell", "-c", "ls"])
Answer from Czaporka on Stack Overflow Top answer 1 of 2
8
The stack trace suggests you're using Windows as the operating system. ls not something that you will typically find on a Windows machine unless using something like CygWin.
Instead, try one of these options:
# use python's standard library function instead of invoking a subprocess
import os
os.listdir()
# invoke cmd and call the `dir` command
import subprocess
subprocess.run(["cmd", "/c", "dir"])
# invoke PowerShell and call the `ls` command, which is actually an alias for `Get-ChildItem`
import subprocess
subprocess.run(["powershell", "-c", "ls"])
2 of 2
3
ls is not a Windows command. The windows analogue is dir, so you could do something like
import subprocess
subprocess.run(['cmd', '/c', 'dir'])
However, if you're really just trying to list a directory it would be much better (and portable) to use something like os.listdir()
import os
os.listdir()
or pathlib
from pathlib import Path
list(Path().iterdir())
DataCamp
datacamp.com โบ tutorial โบ python-subprocess
An Introduction to Python Subprocess: Basics and Examples | DataCamp
September 12, 2025 - In this article, we'll explore the basics of the subprocess module, including how to run external commands, redirect input and output, and handle errors. Whether you're a beginner or an experienced Python developer, this tutorial will provide you with the knowledge you need to use the subprocess module effectively in your projects.
Videos
09:57
Using the Python subprocess Module: Gettting Started & Using ...
19:01
Python Tutorial: Calling External Commands Using the Subprocess ...
13:17
Python 3 Programming Tutorial - Subprocess module - YouTube
52:46
Practical introduction to Python's subprocess module - YouTube
13:34
Python Standard Library: Subprocess - YouTube
10:03
Run Windows Programs Using Python Subprocess Code Example 2023 ...
DigitalOcean
digitalocean.com โบ community โบ tutorials โบ how-to-use-subprocess-to-run-external-programs-in-python-3
How To Use subprocess to Run External Programs in Python 3 | DigitalOcean
July 30, 2020 - The subprocess module is a powerful part of the Python standard library that lets you run external programs and inspect their outputs easily. In this tutorial, you have learned to use subprocess.run to control external programs, pass input to them, parse their output, and check their return codes.
W3Schools
w3schools.com โบ python โบ ref_module_subprocess.asp
Python subprocess Module
Python Examples Python Compiler Python Exercises Python Quiz Python Challenges Python Practice Problems Python Server Python Syllabus Python Study Plan Python Interview Q&A Python Bootcamp Python Certificate Python Training ... import subprocess result = subprocess.run(['echo', 'Hello from Emil'], capture_output=True, text=True) print(result.stdout) Try it Yourself ยป
Codecademy
codecademy.com โบ article โบ python-subprocess-tutorial-master-run-and-popen-commands-with-examples
Python Subprocess Tutorial: Master run() and Popen() Commands (with Examples) | Codecademy
Learn how to use Pythonโs `subprocess` module, including `run()` and `Popen()` to execute shell commands, capture output, and control processes with real-world examples.
Simplilearn
simplilearn.com โบ home โบ resources โบ software development โบ python subprocess: master external command execution
Python Subprocess: Master External Command Execution
December 15, 2025 - Learn about Python's subprocess module for executing external commands. Discover how to manage processes and handle inputs/outputs efficiently.
Address ย 5851 Legacy Circle, 6th Floor, Plano, TX 75024 United States
Python 101
python101.pythonlibrary.org โบ chapter19_subprocess.html
Chapter 19 - The subprocess Module โ Python 101 1.0 documentation
In this code example, we create an args variable to hold our list of arguments. Then we redirect standard out (stdout) to our subprocess so we can communicate with it. The communicate method itself allows us to communicate with the process we just spawned. We can actually pass input to the ...
Pythonspot
pythonspot.com โบ python-subprocess
Python Subprocess โ Tutorial with Examples
If you are new to Python programming, I highly recommend this book. ... I just want to say These are the best tutorials of any anywhere. I use tutorials all the time and these are just so concise and effective. Thanks a lot and keep at it! ... Thanks Kheenan! ... I've copy it and run it . it show me: from subprocess import Popen, PIPE process = Popen(['cat', 'test.py'], stdout=PIPE, stderr=PIPE) stdout, stderr = process.communicate() print stdout Traceback (most recent call last): File "C:\Python27\learn\subprocess.py", line 5, in process = Popen(['cat', 'test.py'], stdout=PIPE, stderr=PIPE) File "C:\Python27\lib\subprocess.py", line 710, in __init__ errread, errwrite) File "C:\Python27\lib\subprocess.py", line 958, in _execute_child startupinfo) WindowsError: [Error 2]