Skip to content

Instantly share code, notes, and snippets.

@simonw
Created September 30, 2010 09:39
Show Gist options
  • Save simonw/604302 to your computer and use it in GitHub Desktop.
Save simonw/604302 to your computer and use it in GitHub Desktop.
"""
Here's how to run a command from Python piping a string in to stdin and reading the
output back in to another string. It took me way too long to work this out.
"""
from subprocess import Popen, PIPE
output = Popen(
['java', '-jar', 'yuicompressor-2.4.2.jar', '--type=css'],
stdin=PIPE, stdout=PIPE
).communicate(input='/* a comment */ .foo {color: red}')[0]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment