Skip to main content

subprocess-tee

Project description

subprocess-tee

This package provides an drop-in alternative to subprocess.run that captures the output while still printing it in real time, just the way tee does.

Printing output in real-time while still capturing is important for any tool that executes long running child processes, as you may not want to deprive user from getting instant feedback related to what is happening.

# from subprocess import run
from subprocess_tee import run

result = run("echo 123")
result.stdout == "123\n"

Rich extension

This libary also provides an drop-in replacement for rich Console class, one that is able to rewire both sys.stdout and sys.stderr and avoid the need too replace bare print() calls with console.print() ones.

# from rich.console import Console
from subprocess_tee.rich import ConsoleEx

console = ConsoleEx(redirect=True, record=True)
print("123")
assert "123\n" == console.export_text()

When used in conjuction with our own run(), this also makes it possible to use rich to process output produced by subprocesses.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

subprocess-tee-0.1.4.tar.gz (13.2 kB view hashes)

Uploaded Source

Built Distribution

subprocess_tee-0.1.4-py3-none-any.whl (7.1 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page