How to run an EXE with input arg, capture output?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Mike Driver
    New Member
    • Nov 2010
    • 5

    How to run an EXE with input arg, capture output?

    Python 2.5, Windows XP.

    I am not a programmer by training/education, and fairly new to using Python but am getting things to work... This really has me stumped - I think obviously over my head. Please excuse my likely obvious lack of finesse with coding and Python. Thanks for any help in adavance.

    I could use help with this within the next 24 hours.

    I have an exe (.bat file, too -- not sure which would be best to use to make this work) which opens a gui where a user supplies a .txt file (containing numerous lines of <value> <frequency>). Also on the gui is a 'compute' button. Once this is clicked, several values are output onto text boxes on the gui. I am particularly interested in capturing one of these output values (EPC, at bottom of attached image). Also interested in sending the input .txt file to the exe (or should it be the bat file?), having the exe execute/compute automatically.

    How should this be done?

    So far, I have tried
    Code:
    import subprocess
    halls = subprocess.Popen([r'C:\Halls\hallbig2.exe'], stdin=subprocess.PIPE, stdout=subprocess.PIPE) 
    result = halls.communicate(input=r'C:\Halls\Input\Ea39j.txt')[0] 
    print halls.returncode
    print halls.communicate()
    The exe runs, but the .txt file is not put into the input box. Once I put it in, and I hit the 'compute' button, the exe runs and outputs the data, and I exit out of the tool, and I get this return
    >>0
    >>('', None)

    This doesn't seem close. I have tried several similar code lines, but am just not getting anywhere. Help!
    Attached Files
  • Mike Driver
    New Member
    • Nov 2010
    • 5

    #2
    No responses thus far... so is this impossible (doubt it)???? If so, could someone please verify? Just gotta know so we can re-think the concept and let client know. This is really a small piece to the puzzle, but getting this idea to work would make running numerous remediation scenarios a lot more efficient, less tedious.

    Comment

    • bvdet
      Recognized Expert Specialist
      • Oct 2006
      • 2851

      #3
      Typically in a Python script you would pass arguments at the command prompt like this:
      python script.py argument1 argument2

      In the script, the arguments are accessed like this:
      Code:
      import sys
      # Name of script
      sys.argv
      # argument 1
      sys.argv[1]
      # argument 2
      sys.argv[2]
      Have you tried that with your executable or bat file?

      I would use a file browse widget to enter the file name. In Tkinter, the tkFileDialog module provides askopenfilename (option=value, ...) and asksaveasfilena me(option=value , ...) to access a browse window.

      There are many was of accessing the results.
      Write the results to disk.

      Write the results to a Text widget where you can manually select and copy.

      If you only need one field, add code to the calc button command to select the result which places the result on the clipboard. This works using a Tkinter Entry widget.

      Comment

      • Mike Driver
        New Member
        • Nov 2010
        • 5

        #4
        This code worked

        Code:
        from pywinauto.application import Application
        app = Application()
        app.start_(r'C:\temp\hallbig2.exe')
        app.Form1.Edit6.TypeKeys(r'C:\temp\input\Ea39j.txt')
        E_Value = ""
        while (E_Value == ""):
            app.Form1.Compute.Click()
            E_Value = app.Form1.Edit8.WindowText()
        print repr(E_Value)
        app.Kill_()

        Comment

        Working...