Open links in new tab
  1. The subprocess module in Python allows you to spawn new processes, connect to their input/output/error pipes, and obtain their return codes. This module is intended to replace several older modules and functions like os.system, os.spawn*, and os.popen.

    Basic Usage

    The most common way to use the subprocess module is through the subprocess.run() function. This function runs a command, waits for it to complete, and then returns a CompletedProcess instance. Here is a basic example:

    import subprocess

    # Run a simple command
    result = subprocess.run(['ls', '-l'], capture_output=True, text=True)

    # Print the output
    print(result.stdout)
    Copied!

    In this example, the capture_output=True argument captures the standard output and error streams, and text=True ensures that the output is returned as a string rather than bytes.

    Advanced Usage with Popen

    For more advanced use cases, you can use the subprocess.Popen class, which offers more control over the process. This class allows you to start a process and interact with its standard input, output, and error streams.

  1. Python subprocess module - GeeksforGeeks

    Apr 4, 2026 · The subprocess module is used to run external programs or system commands from Python. It allows to execute commands, capture their output and interact with other processes.

  2. Python subprocess Module - W3Schools

    The subprocess module allows you to spawn new processes, connect to their input/output/error pipes, and obtain return codes. Use it to execute external commands, run shell scripts, or interact with other …

  3. The subprocess Module: Wrapping Programs With Python

    Jan 18, 2025 · By using subprocess, you can execute shell commands like ls or dir, launch applications, and handle both input and output streams. This module …

  4. An Introduction to Python Subprocess: Basics and Examples

    Apr 23, 2026 · Learn how to use the Python subprocess module to run external commands, redirect input and output, and handle errors. See examples of automating system tasks, running command …

  5. Python Subprocess Tutorial: Master run() and Popen() …

    Learn how to use Python’s `subprocess` module, including `run ()` and `Popen ()` to execute shell commands, capture output, and control processes with real-world …

  6. How to Use subprocess Module in Python - oneuptime.com

    Jan 25, 2026 · Learn how to use Python's subprocess module to run external commands, capture output, handle pipes, and automate system tasks safely and effectively. The subprocess module lets you …

  7. Subprocess in Python

    We will learn about this feature of Python using the module names ‘subprocess’. So let us start with an introduction to the subprocess in Python. What is Subprocess …

  8. subprocess.run · PyPI

    Nov 16, 2013 · To use pipe from the shell. You can install it from PyPi, by simply pip: to test it, launch python. The subprocess module extension to run processes.

  9. python - How to use `subprocess` command with pipes

    Nov 11, 2012 · To use a pipe with the subprocess module, you can pass shell=True but be aware of the Security Considerations. It is discouraged using shell=True. …

  10. People also ask
    Loading
    Unable to load answer