This is a pre-production deployment of Warehouse, however changes made here WILL affect the production instance of PyPI.
Latest Version Dependencies status unknown Test status unknown Test coverage unknown
Project Description

popen

What is it?

The popen package provides a simple shell-like syntax inside python for running external commands.

Features:

  • Chaining (aka. piping) as Sh('ls') | 'sort'
  • Redirect stderr to stdout as Sh('make').include_stderr | 'wc'
  • Redirect output to file as Sh('ls') > '~/listing.txt'
  • Iteration over output lines as for line in Sh('ls'):
  • Streaming input into commands in the chain as Sh.pipe('~/listing.txt').Sh('grep', '-q', 'code').returncode
  • Expands special characters (~*!?)
  • Expands env vars ($HOME) as print Sh('ls', '$USER', '~/*')
  • Properly splits strings ('echo "hole in one"' becomes ['echo', 'hole in one'])
  • Or iterable arguments (Sh('ls', '-l') | ['wc', '-l'] > '/dev/null')

TL;DR

Installation:

pip install popen

Example:

from popen import Sh
for line in Sh('du', '~/') | 'head -n 10' | 'sort -n':
    print('GOT', line)

Usage

Simples usage, run a command and iterate the output lines:

from popen import Sh
for line in Sh('ls', '-la', '~'):
    print line

Piping that output to a file:

Sh('ls', '-la', '~') > '~/listing'

Note that special characters like ~ are expanded, as are environment variables (e.g. $HOME).

Chaining commands is trivial, here with append instead of write to file:

Sh('ls') | Sh('sort') >> '~/listing'

But the right hand side of | can be very flexible, as it employs lexical splitter on string input or takes an iterable:

Sh('ls', '-la', '~') | 'sort -c' | ['uniq', '-c'] | 'tail' | Sh('wc') > '~/listing'

To run a command and let output go to stdout, ask for the return code:

cmd = Sh('ls') | 'grep polka'
print cmd.returncode

To pipe a string into a command, wrap in an iterable:

print Sh.pipe(['this is a \nmulti line\nstring.']) | 'wc'
Release History

Release History

0.1.20

This version

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.1.19

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.1.18

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.1.17

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.1.15

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.1.14

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.1.13

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.1.12

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

Download Files

Download Files

TODO: Brief introduction on what you do with files - including link to relevant help section.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
popen-0.1.20.tar.gz (7.0 kB) Copy SHA256 Checksum SHA256 Source Jan 29, 2015

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS HPE HPE Development Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting