I'm trying to add a try/except
to my subprocess.
try:
mountCmd = 'mount /dev/%s %s%s' % (splitDevice, homeDir, splitDevice)
dev = '/dev/%s' % splitDevice
subprocess.check_call(mountCmd, shell=True)
except subprocess.CalledProcessError:
continue
The above snipet works, but if the host executes the code on a Python version below 2.5 the code will fail since CalledProcessError
was introduced in Python version 2.5.
Does anybody know of a substitute I can use for the CalledProcessError
module?
EDIT: This is how I solved my issue
mountCmd = 'mount /dev/%s %s%s' % (splitDevice, homeDir, splitDevice)
dev = '/dev/%s' % splitDevice
returnCode = 0
#CalledProcessError module was introduced in version 2.5 of python. If older version do the following.
if sys.hexversion < 0x02050000:
try:
p3 = subprocess.Popen(mountCmd, shell=True, stdout=subprocess.PIPE)
output = p3.communicate()[0]
returnCode = p3.returncode
except:
pass
if returnCode != 0:
continue
else: #If version of python is newer than 2.5 use CalledProcessError.
try:
subprocess.check_call(mountCmd, shell=True)
except subprocess.CalledProcessError, e:
continue