Created
March 11, 2014 15:41
-
-
Save s4553711/9488399 to your computer and use it in GitHub Desktop.
Some example for subprocess.Popen exception example
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
#!/usr/bin/python | |
import subprocess | |
import os | |
import sys | |
#res = subprocess.Popen(['ls','-al','/ahome'],stdout=subprocess.PIPE,stderr=subprocess.PIPE); | |
#output,error = res.communicate() | |
#if res.returncode: | |
# #raise Exception(error) | |
# print "error>>>> ",res.returncode | |
#else: | |
# print "output>>>> ",output | |
try: | |
res = subprocess.Popen(['ls','-al','/home'],stdout=subprocess.PIPE,stderr=subprocess.PIPE); | |
#res = subprocess.Popen(['xls','-al','/home'],stdout=subprocess.PIPE); | |
output,error = res.communicate() | |
if output: | |
print "ret> ",res.returncode | |
print "OK> output ",output | |
if error: | |
print "ret> ",res.returncode | |
print "Error> error ",error.strip() | |
#except CalledProcessError as e: | |
# print "CalledError > ",e.returncode | |
# print "CalledError > ",e.output | |
except OSError as e: | |
print "OSError > ",e.errno | |
print "OSError > ",e.strerror | |
print "OSError > ",e.filename | |
except: | |
print "Error > ",sys.exc_info()[0] |
Great! Appreciate the share 👍
so we can add wait() system call after res = subprocess.Popen ??
thanks for sharing
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thanks for sharing