Last active
October 1, 2015 10:57
-
-
Save techtonik/1978810 to your computer and use it in GitHub Desktop.
Python - runout() and runret() functions
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
""" https://gist.github.com/1978810 | |
shutil.runret() and shutil.runout() functions | |
runret(command) - run command through shell, return ret code | |
runout(command) - run command through shell, return output | |
Public Domain, i.e. free for copy/paste | |
https://groups.google.com/d/topic/python-ideas/u42aZZnrs8A/discussion | |
https://bitbucket.org/techtonik/shellrun | |
""" | |
import subprocess | |
def runret(command): | |
""" Run command through shell, return ret code """ | |
# [ ] silence all output | |
return subprocess.call(command, shell=True) | |
def runout(command): | |
""" Run command through shell, return output (stdout + stderr) | |
[ ] cyclic buffer reader in separate thread to avoid deadlock | |
if process writes too much | |
""" | |
return subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, | |
stderr=subprocess.STDOUT).communicate()[0] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See https://bitbucket.org/techtonik/shutil-run/ for more pythonic alternative.