Last active
August 4, 2017 22:33
-
-
Save holocronweaver/a750e508a4257e48ea256aff59478960 to your computer and use it in GitHub Desktop.
Example of capturing Bash output in Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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