Skip to content

Instantly share code, notes, and snippets.

@capttwinky
Created August 13, 2012 20:28
Show Gist options
  • Select an option

  • Save capttwinky/3343883 to your computer and use it in GitHub Desktop.

Select an option

Save capttwinky/3343883 to your computer and use it in GitHub Desktop.
shell command to string
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
@munro
Copy link

munro commented Aug 15, 2012

you should rename your module to le_joel

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment