Created
May 30, 2013 06:13
-
-
Save inetfuture/5675996 to your computer and use it in GitHub Desktop.
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
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