Guest User

Untitled

a guest
Feb 19th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. def stream_command(command):
  2. executable_command = str(command)
  3. print '=>$ %s' % executable_command
  4.  
  5. import subprocess
  6. import sys
  7. try:
  8. process = subprocess.Popen(executable_command, stderr=subprocess.PIPE, stdout=subprocess.PIPE)
  9. comms = process.communicate()
  10. stdout = comms[0]
  11. stderr = comms[1]
  12. print stdout
  13. if process.returncode != 0:
  14. print '[Error %s] %s' % (process.returncode, (stderr or 'See above output'))
  15. stop_the_world(process.returncode)
  16.  
  17. except (OSError, ValueError) as e:
  18. print >>sys.stderr, e
  19. if hasattr(e, 'errno'):
  20. stop_the_world(e.errno)
  21. stop_the_world()
  22.  
  23. def stop_the_world(exit_status=1):
  24. import sys
  25. sys.exit(exit_status)
  26.  
  27. # stream_command('git status')
Add Comment
Please, Sign In to add comment