Announcement

Collapse
No announcement yet.

call osfmount with python script

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • ttaylor
    replied
    Originally posted by ttaylor View Post
    Thanks. I figured it was me, but I thought I would ask.
    Here is my test code that works...

    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)
    Last edited by ttaylor; Jan-09-2013, 07:02 PM. Reason: Correct code errors

    Leave a comment:


  • ttaylor
    replied
    Originally posted by David (PassMark) View Post
    While I have done programming in maybe a dozen different languages, Python isn't one of them.

    If, as you say, you have it working from the command line, then there is probably some silly syntax error in your Python script.
    Thanks. I figured it was me, but I thought I would ask.

    Leave a comment:


  • David (PassMark)
    replied
    While I have done programming in maybe a dozen different languages, Python isn't one of them.

    If, as you say, you have it working from the command line, then there is probably some silly syntax error in your Python script (that isn't obvious to me).

    Leave a comment:


  • ttaylor
    started a topic call osfmount with python script

    call osfmount with python script

    I'm attempting to right a python script to mount e01 files using osfmount. The command line I'm using works in the terminal, but not in my script. Is there something special I need to do?

    I'm using python 3.3 and subprocess.check_output command. The gui pops up instead of mounting the image.

    Pertinent lines of code I'm using:
    Code:
    image_file=r'G:\TestImages\myimage.E01'
    cmd_line='osfmount -a -t file -f  ' + image_file + ' -m #:'
    ret_string = subprocess.check_output(cmd_line)
    I'm fairly new at python, but I think this should work.
Working...
X