Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save inetfuture/5675996 to your computer and use it in GitHub Desktop.
Save inetfuture/5675996 to your computer and use it in GitHub Desktop.
import subprocess
def execute(command):
process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
output = ''
# Poll process for new output until finished
for line in iter(process.stdout.readline, ""):
print line,
output += line
process.wait()
exitCode = process.returncode
if (exitCode == 0):
return output
else:
raise Exception(command, exitCode, output)
execute(['ping', 'localhost'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment