Skip to content

Instantly share code, notes, and snippets.

@holocronweaver
Last active August 4, 2017 22:33
Show Gist options
  • Save holocronweaver/a750e508a4257e48ea256aff59478960 to your computer and use it in GitHub Desktop.
Save holocronweaver/a750e508a4257e48ea256aff59478960 to your computer and use it in GitHub Desktop.
Example of capturing Bash output in Python
from subprocess import check_output
def sh(x): return check_output(x, shell=True).decode()
def script(x):
return sh("""
derp () {{
printf "hello %d\\n" {0}
sha256sum example.py
}}
derp "world"
""".format(x))
s = script(42)
print(s)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment