Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > How to run an EXE, with argument, capture output value

Reply
Thread Tools

How to run an EXE, with argument, capture output value

 
 
noydb
Guest
Posts: n/a
 
      11-18-2010
On Nov 18, 6:20*pm, noydb <(E-Mail Removed)> wrote:
> On Nov 18, 5:54*pm, noydb <(E-Mail Removed)> wrote:
>
>
>
>
>
> > On Nov 18, 5:22*pm, Tim Harig <(E-Mail Removed)> wrote:

>
> > > On 2010-11-18, noydb <(E-Mail Removed)> wrote:

>
> > > > import subprocess
> > > > pig = subprocess.Popen(["C:\Halls\hallbig2.exe"],
> > > > stdin=subprocess.PIPE, stdout=subprocess.PIPE)
> > > > result = pig.communicate(input='C:\Halls\Input\Ea39j.txt')[-1] #I need
> > > > to capture the, what I think is the, last output

>
> > > From the subprocess documentation:

>
> > > * * * * * *[62]communicate() returns a tuple (stdoutdata, stderrdata).
> > > * * * * * *Note that if you want to send data to the process's stdin,
> > > * * * * * *you need to create the Popen object with stdin=PIPE. Similarly,
> > > * * * * * *to get anything other than None in the result tuple, you need
> > > * * * * * *to give stdout=PIPE and/or stderr=PIPE too..

>
> > > By using index [-1] you are accessing the processes stderr stream. *I am
> > > not really sure why you changed it. *It doesn't give you the last output.
> > > Index 0 gives you *all* of stdout and index 1 gives you *all* of stderr,
> > > period. *If you wish to further disect the output to get say the last line,
> > > then you will need to parse it separately.

>
> > Okay, I see now. *I did run it to start with 0 -- still same result no
> > matter if 0 or -1.
> > So, what is result (stdout, using [0]) in this case? *(yes, i know I
> > sound dumb - programming is not my background, obviously). *A list,
> > tuple??? *How do you access stdout (or is it stdoutdata?) results? *I
> > have tried, get errors with all attempts. *The exe gui returns several
> > statistical values uopn inputing a text file (containing numerous
> > lines of <value> <frequency>) and clicking compute - I want just one
> > of the values.

>
> > > > print result
> > > > print pig.returncode
> > > >>> None
> > > >>> 0

>
> > > > So the tuple is empty. ?? *The exe executes fine and returns output in
> > > > th exe tool itself. *The python script seems to execute fine, no
> > > > errors, '...returned exit code 0'. *Any ideas/suggestions?

>
> > > No the tuple contains two items (stdout, stderr). *The first is what the
> > > program printed to its stdout stream (which is most likely the output you
> > > see if you run the command at a terminal/console). *The second is what it printed to its
> > > stderr stream which is a channel used for out of band data such as error or
> > > status messages. *In this case, it is None, because you did open stderr as a
> > > subprocess.PIPE.- Hide quoted text -

>
> > - Show quoted text -- Hide quoted text -

>
> > - Show quoted text -

>
> stdout is a file object- Hide quoted text -
>
> - Show quoted text -


if I do
>>> print pig.communicate()

('', None)

Doesn't that mean it is empty?
 
Reply With Quote
 
 
 
 
noydb
Guest
Posts: n/a
 
      11-19-2010
Any other help? I am guessing not, just wanted to try one more time.
Could really use help, please!!

 
Reply With Quote
 
 
 
 
Jerry Hill
Guest
Posts: n/a
 
      11-19-2010
On Fri, Nov 19, 2010 at 9:52 AM, noydb <(E-Mail Removed)> wrote:
> Any other help? *I am guessing not, just wanted to try one more time..
> Could really use help, please!!


You'll need to give us more information about the program you're
trying to automate. It originally sounded like you just needed to run
a console program, where it's usually fairly easy to run and capture
the output with the subprocess module. Now it sounds like you're
trying to automate a GUI that requires user interaction. That's quite
a bit more complicated.

When you run "stats_hall.exe", what do you get on the screen? What,
exactly, are the steps a normal user would need to perform to do what
you want to automate? After the values you're interested in are
computed, where do they show up? Is this program publically available
someplace?

I've generally had good luck doing simple GUI automation with
pywinauto. The homepage appears to be: http://pywinauto.pbworks.com
which has installation instructions and a FAQ. You might also find
this demo useful:
http://showmedo.com/videotutorials/v...owsApplication

--
Jerry
 
Reply With Quote
 
Tim Harig
Guest
Posts: n/a
 
      11-19-2010
C:\Documents and Settings\Tim Harig\My Documents\autoCalc>dir
Volume in drive C has no label.
Volume Serial Number is 30D9-35E0

Directory of C:\Documents and Settings\Tim Harig\My Documents\autoCalc

11/19/2010 12:20 PM <DIR> .
11/19/2010 12:20 PM <DIR> ..
11/19/2010 12:19 PM 686 autoCalc.pys
1 File(s) 686 bytes
2 Dir(s) 16,343,552,000 bytes free

C:\Documents and Settings\Tim Harig\My Documents\autoCalc>type autoCalc.pys
# autoCalc.pys: The "pys" extension indicates that it should be run under
# Windows Script Host

# perform the calculation using Windows calculator
keySequence = ['2', '{+}', '2', '=', '^c', '%{F4}']
WshShell = WScript.CreateObject("WScript.Shell")
calculator = WshShell.Run("calc")
WshShell.AppActivate("calc")
WScript.Sleep(1000)
for currentKey in keySequence:
WshShell.SendKeys(currentKey)
WScript.Sleep(100)

# write the results to notepad and same as demo.txt
keySequence = ['result: ', '^v', '^s',
'c:\\Documents and Settings\\Tim Harig\\My Documents\\autoCalc\\demo.txt',
'~', '%{F4}']
notepad = WshShell.Run("notepad")
WshShell.AppActivate("notepad")
WScript.Sleep(1000)
for currentKey in keySequence:
WshShell.SendKeys(currentKey)
WScript.Sleep(100)

C:\Documents and Settings\Tim Harig\My Documents\autoCalc>cscript.exe autoCalc.pys
Microsoft (R) Windows Script Host Version 5.7
Copyright (C) Microsoft Corporation. All rights reserved.

Debugging extensions (axdebug) module does not exist - debugging is disabled..

C:\Documents and Settings\Tim Harig\My Documents\autoCalc>type demo.txt
result: 4
C:\Documents and Settings\Tim Harig\My Documents\autoCalc>
 
Reply With Quote
 
noydb
Guest
Posts: n/a
 
      11-20-2010
Thanks to Jerry Hill above who helped.
This worked:

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_()
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
How to run one script from another, and capture the output John Smith Ruby 7 12-30-2009 06:00 PM
Screen Capture With Mouse , Mouse Position Capture Max Java 7 08-08-2009 11:51 PM
SuperVideoCap work as a broadcast capture and screen capture and record tool. hely0123 Media 0 10-30-2007 08:59 AM
run perl script and capture the output Li Chen Ruby 0 12-20-2006 04:25 AM



Advertisments