Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (
Help us improve Python packaging - Donate today!

running commands through a system shell

Project Description

Look at envoy first. waits for completion before returning output, which is not what you need when wrapping long running tools, where output needed as soon as it appears, does not intercept output - there is a separate command for that.

>>> import shellrun
>>> r ='uptime')
 04:06:37 up 2 min,  1 user,  load average: 0.20, 0.19, 0.08
>>> r.output
>>> r.success
>>> r.retcode

To capture output envoy-style, use run_capture. stdout and stderr are merged, because that’s how users see it:

>>> r = shellrun.run_capture('uptime')
>>> r.output
' 04:07:16 up 2 min,  1 user,  load average: 0.11, 0.17, 0.08\n'
>>> r.success
>>> r.retcode

Quick comparison of result objects:

envoy.Response shellrun.Result
.command .command
.status_code .retcode

Example of .success usage:

from shellrun import run_capture

r = run_capture('ls -la')
if r.success:
    print("Error: '%s' exit code %s" % (r.command, r.retcode))
    print("         ...")
    # print last three lines of output
    for line in r.output.splitlines()[-3:]:
        print("       %s" % line)

Release History

This version
History Node


Download Files

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

Filename, Size & Hash SHA256 Hash Help File Type Python Version Upload Date
(3.9 kB) Copy SHA256 Hash SHA256
Source None Oct 12, 2014

Supported By

Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Kabu Creative Kabu Creative UX & Design Google Google Cloud Servers Fastly Fastly CDN StatusPage StatusPage Statuspage DigiCert DigiCert EV Certificate