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
🌐
Python
docs.python.org › 3 › library › subprocess.html
subprocess — Subprocess management
1 week ago - To determine if the shell failed to find the requested application, it is necessary to check the return code or output from the subprocess. A ValueError will be raised if Popen is called with invalid arguments. check_call() and check_output() will raise CalledProcessError if the called process returns a non-zero return code. All of the functions and methods that accept a timeout parameter, such as run() and Popen.communicate() will raise TimeoutExpired if the timeout expires before the process exits.
🌐
DataCamp
datacamp.com › tutorial › python-subprocess
An Introduction to Python Subprocess: Basics and Examples | DataCamp
September 12, 2025 - Using the Python subprocess module ... tasks and integrate other programs with your Python code. For example, you can use the subprocess module to run a shell command, like ls or ping, and get the output of that command in your Python code....
🌐
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 - As an example, this pattern could be useful if we wanted to raise an exception in the event that we run git ls-files in a directory that wasn’t actually a git repository. We can use the check=True keyword argument to subprocess.run to have an exception raised if the external program returns a non-zero exit code:
🌐
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
Note: This code’s output will ... named my_python_file.py in this example. ... The subprocess.run() function is used here to execute another Python file....
🌐
Dataquest
dataquest.io › blog › python-subprocess
Python Subprocess: The Simple Beginner's Tutorial (2023)
February 19, 2025 - In fact, this is the same as passing /usr/local/bin/python -c print('This is a subprocess') to the command line. Most of the code in this article will be in this format because it's easier to show the features of the run function.
🌐
Python Morsels
pythonmorsels.com › running-subprocesses-in-python
Running subprocesses in Python - Python Morsels
March 6, 2025 - Note that a subprocess (as I'm defining it) is not related to our process: it's not "forked" from our process, but instead is a separate application which is usually not even a Python process. To run a process, we can use the subprocess module's run function:
🌐
Real Python
realpython.com › python-subprocess
The subprocess Module: Wrapping Programs With Python – Real Python
January 18, 2025 - In this section, you’ll take a look at some of the most basic examples demonstrating the usage of the subprocess module. You’ll start by exploring a bare-bones command-line timer program with the run() function.
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-subprocess-module
Python subprocess module - GeeksforGeeks
2 weeks ago - subprocess.run() executes a command and waits until it finishes. It returns an object that contains output, errors and return status of the command. Example: Here, a command is executed and both output and return code are printed.
🌐
Medium
medium.com › @AlexanderObregon › how-to-use-pythons-subprocess-module-to-run-system-commands-ffdeabcb9721
How to Use Python’s subprocess Module to Run System Commands
November 12, 2024 - Learn how to execute system commands in Python using the subprocess module, with examples of capturing output, handling errors, and running pipelines.
🌐
Earthly
earthly.dev › blog › python-subprocess
How to Use Python's Subprocess Module - Earthly Blog
July 11, 2023 - Learn how to use Python's subprocess module to run external commands, capture and process outputs, redirect output to files, and more. This tut...
🌐
Python for Network Engineers
pyneng.readthedocs.io › en › latest › book › 12_useful_modules › subprocess.html
subprocess - Python for network engineers
In [7]: result = subprocess.run('ls -ls *md', shell=True) 4 -rw-r--r-- 1 vagrant vagrant 56 Jun 7 19:35 ipython_as_mngmt_console.md 4 -rw-r--r-- 1 vagrant vagrant 1638 Jun 7 19:35 module_search.md 4 -rw-r--r-- 1 vagrant vagrant 277 Jun 7 19:35 README.md 4 -rw-r--r-- 1 vagrant vagrant 49 Jun 7 19:35 version_control.md · Another feature of run() If you try to run a ping command, for example, this aspect will be visible:
🌐
Better Stack
betterstack.com › community › guides › scaling-python › python-subprocess
An Introduction to Python Subprocess | Better Stack Community
The subprocess module provides several functions for creating and interacting with subprocesses, with run() and Popen() being the most commonly used. Let's start with the simplest example using the high-level run() function, which was introduced in Python 3.5.
🌐
Python Land
python.land › home › interaction with the operating system › python subprocess: run external commands
Python Subprocess: Run External Commands • Python Land Tutorial
October 30, 2024 - Learn how to execute external command with Python using the subprocess library. With examples to run commands, capture output, and feed stdin
🌐
Linux find Examples
queirozf.com › entries › python-3-subprocess-examples
Python 3 Subprocess Examples
November 26, 2022 - See Popen() vs call() vs run() This causes the python program to block until the subprocess returns. from subprocess import Popen p = Popen(["ls","-lha"]) p.wait() # 0
🌐
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 Module of the Week
pymotw.com › 2 › subprocess
subprocess – Work with additional processes - Python Module of the Week
The default is to run the command directly. import subprocess # Command with shell expansion subprocess.call('echo $HOME', shell=True)
🌐
PyPI
pypi.org › project › subprocess.run
subprocess.run · PyPI
>>> from subprocess import run >>> run('uname -r').stdout 3.7.0-7-generic >>> run('uname -a').status 0 >>> print run('rm not_existing_directory').stderr rm: cannot remove `not_existing_directory': No such file or directory >>> print run('ls -la', 'wc -l') 14
      » pip install subprocess.run
    
Published   Nov 16, 2013
Version   0.0.8
🌐
Python Module of the Week
pymotw.com › 3 › subprocess
subprocess — Spawning Additional Processes
March 18, 2018 - The command line arguments are passed as a list of strings, which avoids the need for escaping quotes or other special characters that might be interpreted by the shell. run() returns a CompletedProcess instance, with information about the process like the exit code and output. $ python3 subprocess_os_system.py index.rst interaction.py repeater.py signal_child.py signal_parent.py subprocess_check_output_error_trap_output.py subprocess_os_system.py subprocess_pipes.py subprocess_popen2.py subprocess_popen3.py subprocess_popen4.py subprocess_popen_read.py subprocess_popen_write.py subprocess_run_check.py subprocess_run_output.py subprocess_run_output_error.py subprocess_run_output_error_suppress.py subprocess_run_output_error_trap.py subprocess_shell_variables.py subprocess_signal_parent_shell.py subprocess_signal_setpgrp.py returncode: 0
🌐
Python Forum
python-forum.io › thread-39872.html
Using subprocess to execute complex command with many arguments
I have a shell script that is as follows: LOAD_RRD=sysmon.rrd DISK_RRD=disk.rrd DISKTEMP_RRD=disktemp.rrd rrdtool graph load1h.png \ -Y -u 1.1 -l 0 -L 5 -v 'Load' -w 700 -h 200 -t 'Load stats - `/bin/date`' \ --start end-'1h' --x-grid MIN...