By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,818 Members | 1,347 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,818 IT Pros & Developers. It's quick & easy.

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

P: 5
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
Expand|Select|Wrap|Line Numbers
  1. import subprocess
  2. halls = subprocess.Popen([r'C:\Halls\hallbig2.exe'], stdin=subprocess.PIPE, stdout=subprocess.PIPE) 
  3. result = halls.communicate(input=r'C:\Halls\Input\Ea39j.txt')[0] 
  4. print halls.returncode
  5. print halls.communicate()
  6.  
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 Images
File Type: jpg exe_tool_before.jpg (48.1 KB, 577 views)
File Type: jpg exe_tool_after.jpg (58.3 KB, 417 views)
Nov 19 '10 #1
Share this Question
Share on Google+
3 Replies


P: 5
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.
Nov 19 '10 #2

bvdet
Expert Mod 2.5K+
P: 2,851
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:
Expand|Select|Wrap|Line Numbers
  1. import sys
  2. # Name of script
  3. sys.argv
  4. # argument 1
  5. sys.argv[1]
  6. # argument 2
  7. 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 asksaveasfilename(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.
Nov 19 '10 #3

P: 5
This code worked

Expand|Select|Wrap|Line Numbers
  1. from pywinauto.application import Application
  2. app = Application()
  3. app.start_(r'C:\temp\hallbig2.exe')
  4. app.Form1.Edit6.TypeKeys(r'C:\temp\input\Ea39j.txt')
  5. E_Value = ""
  6. while (E_Value == ""):
  7.     app.Form1.Compute.Click()
  8.     E_Value = app.Form1.Edit8.WindowText()
  9. print repr(E_Value)
  10. app.Kill_()
  11.  
Nov 20 '10 #4

Post your reply

Sign in to post your reply or Sign up for a free account.