Runs

1.3.0 · active · verified Thu Apr 09

Runs is a Python library (version 1.3.0) that enhances the standard `subprocess` module by providing improved functions to execute blocks of text as sequences of shell commands. It adds features like multi-command execution, line continuations, comment handling, optional logging, error handling, lazy evaluation, and defaults to UTF-8 encoding. It offers more robust handling for scenarios that often trip up the native `subprocess` functions.

Warnings

Install

Imports

Quickstart

This example demonstrates how to use `runs.run()` to execute a multi-line block of commands and capture their output. It also shows how to enable echoing commands and handle exceptions from failing subprocesses. The library provides a more convenient interface for common shell interactions than the raw `subprocess` module.

from runs import run

# Run a block of text as multiple commands
output = run('''
  echo "Hello from Runs!"
  ls -l
''')

for line in output:
    print(line)

# Run with error handling and echo
try:
    result = run('false; echo ok', on_exception=False, echo=True)
except Exception as e:
    print(f"Caught expected error: {e}")

# Get stdout of a single command
stdout_list = run('echo "Single command output"')
print(stdout_list[0])

view raw JSON →