Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Some example for subprocess.Popen exception example
#!/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]
@pashh

This comment has been minimized.

Copy link

pashh commented Jun 19, 2015

it looks good thank for hint

@youngminz

This comment has been minimized.

Copy link

youngminz commented Dec 4, 2015

Thank you!

@azherullahkhan

This comment has been minimized.

Copy link

azherullahkhan commented Aug 4, 2016

Thank you

@SealedJoy

This comment has been minimized.

Copy link

SealedJoy commented Jan 24, 2019

thanks for sharing 👍 !

@AmirAmraei

This comment has been minimized.

Copy link

AmirAmraei commented Jan 25, 2020

thanks and big like

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.