Code:
import subprocess, re
from time import sleep
image_file=r'G:\TestImages\myimage.E01'
cmd_line=r'osfmount -a -t file -f ' + image_file + ' -m #:'
try:
ret_string = subprocess.check_output(cmd_line, stderr=subprocess.STDOUT, shell=True)
#Get the drive letter
if len(ret_string) > 0:
ret_string=str(ret_string)
m = re.search(r'[a-zA-Z]:\s', ret_string)
drive_letter=m.group(0)
print('Image was mounted on {0}'.format(drive_letter))
#unmount the image
sleep(10)
cmd_line=r'osfmount -d -m ' + drive_letter
retcode=subprocess.check_output(cmd_line, stderr=subprocess.STDOUT, shell=True)
print ('Image on {0} was unmounted'.format(drive_letter))
else:
print('Image was not mounted')
except OSError as e:
print('Execution failed: {0}'.format(e))
except subprocess.CalledProcessError as e:
print (e.output)
Leave a comment: