Open links in new tab
  1. Welcome to Python.org

    1. Python
      Python 0.9.0 released on alt.sources
      1991
    2. Python
      Python 2.0 released with list comprehensions, unicode support
      2000
    3. Python
      PEP 8, Python style guide, published
      2003
    4. Python
      Python 3.0 released with significant changes, backward compatibility breaks
      2008
  1. Python provides several ways to execute shell commands, allowing you to interact with the operating system directly from your Python scripts. This can be useful for automating tasks, managing files, or running system commands.

    Using the os Module

    The os module in Python includes functionality to communicate with the operating system. One of the simplest ways to execute shell commands is by using the os.system() method. This method takes a command as a string and executes it in a subshell.

    Example:

    import os

    # Execute a simple shell command
    os.system('echo "Hello, World!"')

    # Execute a command to list files in the current directory
    os.system('ls -l')
    Copied!

    The os.system() method is straightforward but has limitations, such as not being able to capture the output of the command.

    Using the subprocess Module

    The subprocess module is more powerful and flexible than the os module. It allows you to spawn new processes, connect to their input/output/error pipes, and obtain their return codes.

    Feedback
  2. Executing Shell Commands with Python - GeeksforGeeks

    Feb 14, 2026 · This article starts with a basic introduction to Python shell commands and why one should use them. It also describes the three primary ways to run Python shell commands.

  3. The Xonsh Shell — Python-powered shell. Python shell.

    XONSH is a modern, full-featured and cross-platform python shell that lets you easily mix Python and shell commands. Learn how to install, use and extend …

  4. 2.1 The Python shell - Introduction to Python …

    Most development environments include a Python shell for experimenting with code interactively. A shell, also called a console or terminal, is a program that …

  5. Shell & IDLE: Python code in a terminal or simple IDE

    Mar 13, 2026 · The Python Shell will start and display a prompt (>>>) where you can start entering Python commands. Once the Python shell is running, you can write and execute Python code directly …

  6. People also ask
    Loading
    Unable to load answer
  7. Run Shell Commands in Python and Get Output - PyTutorial

    Feb 19, 2026 · Learn how to execute shell commands from Python using subprocess module, capture output, handle errors, and apply best practices for automation.

  8. Python: Running Shell Commands and Retrieving Output

    Apr 6, 2025 · In this blog post, we will explore the different ways to run shell commands in Python and obtain their output, along with best practices to ensure efficient and reliable code.

  9. python - How do I execute a program or call a system command?

    How do I call an external command within Python as if I had typed it in a shell or command prompt?

  10. How to Execute a Shell Command in Python [Step-by-Step]

    Feb 22, 2021 · Learn how to use os.system, os.popen and subprocess modules to run Linux commands in Python. See examples, output, exit codes and error handling.

  11. IDLE — Python editor and shell — Python 3.14.3 …

    1 day ago · IDLE is a cross-platform integrated development and learning environment for Python. It has features such as colorizing, auto completion, …