Created
August 13, 2012 20:28
-
-
Save capttwinky/3343883 to your computer and use it in GitHub Desktop.
shell command to string
This file contains hidden or 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
| import shlex | |
| import subprocess | |
| from lib_joel import fnprint | |
| class sp_error(StandardError): | |
| pass | |
| def get_out(cmd): | |
| '''execute shell command in subprocess, return result''' | |
| try: | |
| sp = subprocess.Popen(shlex.split(cmd),stdout=subprocess.PIPE, stderr=subprocess.PIPE) | |
| except Exception as e: | |
| raise sp_error('command error: {0}'.format(e)) | |
| stdout, stderr = sp.communicate() | |
| if stderr: raise sp_error(stderr) | |
| return stdout |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
you should rename your module to
le_joel