473,416 Members | 1,542 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,416 software developers and data experts.

Opening an exe

I need to write a program that will open an exe and check some timings in it.

point to exe
run exe
check time taken between numbers:
123 (08 secs)
341 (1 sec)
444 (09 secs)

What python functions do I need to research to accomplish this? Thanks
Feb 6 '07 #1
22 3426
bartonc
6,596 Expert 4TB
I need to write a program that will open an exe and check some timings in it.

point to exe
run exe
check time taken between numbers:
123 (08 secs)
341 (1 sec)
444 (09 secs)

What python functions do I need to research to accomplish this? Thanks
I use _winreg to find out the path of the exe:
Expand|Select|Wrap|Line Numbers
  1.         try:
  2.             ### Read registry for InstaCal path
  3.             instacalKey = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE,
  4.                                         "SOFTWARE\Universal Library")
  5.             self.pmdPath = str(_winreg.QueryValueEx(instacalKey, 'RootDirs')[0])
  6.             instacalKey.Close()
  7.         except WindowsError:
  8.             self.InstaCalBtn.Disable()
  9.             self.pmdPath = ""
then:
Expand|Select|Wrap|Line Numbers
  1.  
  2.     def OnInstaCalButton(self, event):
  3.         os.spawnl(os.P_DETACH, self.pmdPath + "inscal32.exe")
Need more info on the time between numbers, but you might want to check out the time module.
Feb 6 '07 #2
Thank you for the reply. I know the path of the exe. Could I do something like this:

Expand|Select|Wrap|Line Numbers
  1. import os, sys
  2.  
  3. pyPath = "C:\python25\app.exe"
  4.  
As far as the numbers go, the script will need 4 integer variables from 0-1000 and will slow when the right number is crossed and then move on to another series of 0-1000, and continue to loop for a total of 4 times.
Here is a sample C++ code snippet that might help.
ex: system("app.exe1 1 1 1") was used to call the application.

Expand|Select|Wrap|Line Numbers
  1. MaxR = -1.0;
  2. for(i=1; i<1000; i++){
  3.          ... code
  4.  
  5.           system(sRun);
  6.  
  7.     ....code
  8.  
  9.     R = ... the elapsed time of the function system().
  10.     if (R > MaxR){
  11.         MaxR = R;
  12.         MaxI = i;
  13.     }
  14. }
  15.  
  16. printf ("Max(i) = %d  elapsed %.9f  secs \n", MaxI, MaxR);
  17.  
ex: system("app.exe1 1 1 1") was used to call the application. Does python have something similar?
Feb 6 '07 #3
bartonc
6,596 Expert 4TB
Thank you for the reply. I know the path of the exe. Could I do something like this:

Expand|Select|Wrap|Line Numbers
  1. import os, sys
  2.  
  3. pyPath = "C:\python25\app.exe"
  4.  
You must use raw strings or unicode strings for windows path names. Otherwise you get "escape" sequences. ie "C:\test" is actually "C:[tab]est".
Expand|Select|Wrap|Line Numbers
  1. import os, sys
  2. appPath = r"C:\python25\app.exe"
  3. # or
  4. appPath = u"C:\python25\app.exe"
  5.  
I prefer raw strings. Boa Construtor uses unicode strings.
Feb 7 '07 #4
bartonc
6,596 Expert 4TB
As far as the numbers go, the script will need 4 integer variables from 0-1000 and will slow when the right number is crossed and then move on to another series of 0-1000, and continue to loop for a total of 4 times.
Here is a sample C++ code snippet that might help.
ex: system("app.exe1 1 1 1") was used to call the application.

Expand|Select|Wrap|Line Numbers
  1. MaxR = -1.0;
  2. for(i=1; i<1000; i++){
  3.          ... code
  4.  
  5.           system(sRun);
  6.  
  7.     ....code
  8.  
  9.     R = ... the elapsed time of the function system().
  10.     if (R > MaxR){
  11.         MaxR = R;
  12.         MaxI = i;
  13.     }
  14. }
  15.  
  16. printf ("Max(i) = %d  elapsed %.9f  secs \n", MaxI, MaxR);
  17.  
ex: system("app.exe1 1 1 1") was used to call the application. Does python have something similar?
There are a few ways to do this:
Expand|Select|Wrap|Line Numbers
  1. from time import time
  2. startTime = time()
  3. for i in xrange(1000):
  4.     # simulate an external process
  5.     for i in range(10000):
  6.         pass
  7.  
  8. print "Process took %f seconds" % (time() - startTime)

There is a discussion on the timeit module here.
Feb 7 '07 #5
There are a few ways to do this:
Expand|Select|Wrap|Line Numbers
  1. from time import time
  2. startTime = time()
  3. for i in xrange(1000):
  4.     # simulate an external process
  5.     for i in range(10000):
  6.         pass
  7.  
  8. print "Process took %f seconds" % (time() - startTime)

There is a discussion on the timeit module here.
Awesome! That's a great start for me. Thank you! I see what you mean about the raw string as I was getting an error message with app.exe.
Feb 7 '07 #6
bartonc
6,596 Expert 4TB
Awesome! That's a great start for me. Thank you! I see what you mean about the raw string as I was getting an error message with app.exe.
Go get 'me and have fun! Keep posting,
Barton
Feb 7 '07 #7
Ok, so I found a couple of different ways to get python to run the app.exe, but how do I incorporate the timing code to the exe? If I use the following code, it will run, regardless of the app.exe.
Code:
Expand|Select|Wrap|Line Numbers
  1. from time import time
  2. startTime = time()
  3. for i in xrange(1000):
  4.        # simulate an external process
  5. for i in range(1000):
  6.      pass
  7.  
  8. print "Process took %f seconds" % (time() - startTime)
  9.  
This will run the app.exe
Code:
Expand|Select|Wrap|Line Numbers
  1. import subprocess
  2.  
  3. subprocess.Popen(r"C:\python25\app.exe")
  4.  
or this one, which will run the timer and then the app.exe. It sometimes gives me a NameError: name 'MZP' is not defined, but I have no idea where that comes from since there is no 'MZP' in the code.
Code:
Expand|Select|Wrap|Line Numbers
  1. import os,sys
  2.  
  3. pyPath=r"C:\python25\python.exe"
  4. appPath=r"C:\python25\app.exe"
  5. os.spawnv(os.P_NOWAIT,pyPath,["python",appPath])
  6.  
  7. from time import time
  8. startTime = time()
  9. for i in xrange(1000):
  10.     # simulate an external process
  11.     for i in range(10000):
  12.         pass
  13.  
  14. print "Process took %f seconds" % (time() - startTime)
  15.  
  16.  
Feb 8 '07 #8
bartonc
6,596 Expert 4TB
Ok, so I found a couple of different ways to get python to run the app.exe, but how do I incorporate the timing code to the exe? If I use the following code, it will run, regardless of the app.exe.
In the 2.4 Python Manuals the section is "6.1.5 Process Management" of the os module documentation. It describes how you may be able to wait for an exit code from the external process.
Feb 8 '07 #9
dshimer
136 Expert 100+
Expand|Select|Wrap|Line Numbers
  1. import os,sys
  2.  
  3. pyPath=r"C:\python25\python.exe"
  4. appPath=r"C:\python25\app.exe"
  5. os.spawnv(os.P_NOWAIT,pyPath,["python",appPath])
  6.  
This seems to me that it would be on the right track except it looks like it would evaluate out to a command line similar to.

C:\python25\python.exe C:\python25\app.exe

which is just trying to call an executable in python itself or am I missing something? As I play with the spawnv, I would think that you would just want to set a start time, run something like

os.spawnv(os.P_NOWAIT,appPath,["appname",AnyArgsForApp])

then check the end time.
Feb 8 '07 #10
bartonc
6,596 Expert 4TB
Expand|Select|Wrap|Line Numbers
  1. import os,sys
  2.  
  3. pyPath=r"C:\python25\python.exe"
  4. appPath=r"C:\python25\app.exe"
  5. os.spawnv(os.P_NOWAIT,pyPath,["python",appPath])
  6.  
This seems to me that it would be on the right track except it looks like it would evaluate out to a command line similar to.

C:\python25\python.exe C:\python25\app.exe

which is just trying to call an executable in python itself or am I missing something? As I play with the spawnv, I would think that you would just want to set a start time, run something like

os.spawnv(os.P_NOWAIT,appPath,["appname",AnyArgsForApp])

then check the end time.
Yep. It is the right track. It's the "os.P_NOWAIT" that is in question.
Feb 8 '07 #11
dshimer
136 Expert 100+
Should have put this in before, but for example to run the find command on my /tmp directory and time it
Expand|Select|Wrap|Line Numbers
  1. >>> def test():
  2. ...     start=time.time()
  3. ...     os.spawnv(os.P_WAIT,'c:/unix/find.exe',['find','/tmp'])
  4. ...     print time.time()-start
  5. ... 
  6. >>> test()
  7. 0.950999975204
  8.  
Feb 8 '07 #12
dshimer
136 Expert 100+
Yep. It is the right track. It's the "os.P_NOWAIT" that is in question.
Good call, I didn't even catch that in the original post, I just went by the docs which is why the example works, but the answer was incomplete.
Feb 8 '07 #13
bartonc
6,596 Expert 4TB
Good call, I didn't even catch that in the original post, I just went by the docs which is why the example works, but the answer was incomplete.
Great posting, D. I really appreciate all of your input. Thank you,
Barton
Feb 9 '07 #14
Thank you both for your replies! One more thing.....how could I do this:
Expand|Select|Wrap|Line Numbers
  1. i = 0
  2. for i in range(0,30):
  3.      print i
  4.      i +=1 
  5.  
....have the double digits print out with a space between them:
2 0
2 1
2 2 etc...

Would something like this work? i = 0 0?
Feb 9 '07 #15
bartonc
6,596 Expert 4TB
Thank you both for your replies! One more thing.....how could I do this:
Expand|Select|Wrap|Line Numbers
  1. i = 0
  2. for i in range(0,30):
  3.      print i
  4.      i +=1 
  5.  
....have the double digits print out with a space between them:
2 0
2 1
2 2 etc...

Would something like this work? i = 0 0?
Expand|Select|Wrap|Line Numbers
  1. I don't see where the "2" is coming from in your example.
  2. Print will put a space in for you by using the comma.
  3. range() takes (start, [stop], [step]) where braces mean optional parameters.
  4. for i in range(30):
  5.      print 2, i
Feb 9 '07 #16
dshimer
136 Expert 100+
I'll agree with bartonc that I'm not totally positive what you are trying to accomplish, but a quick review of for and range may help.

You don't need to set i=0 because in the
Expand|Select|Wrap|Line Numbers
  1.  for i in range(30):
a start of 0 is implied, though if you need to reset it you can just say
Expand|Select|Wrap|Line Numbers
  1.  for i in range(0,30):
range is just creating a list of numbers, each member of which gets evaluated as i during the loop.
Expand|Select|Wrap|Line Numbers
  1. >>> range(5)
  2. [0, 1, 2, 3, 4]
so it has always seemed to me to be dangerous to modify it inside the loop. Though there may be good reasons to do so.

To reproduce the output you listed
Expand|Select|Wrap|Line Numbers
  1. >>> for i in range(3):
  2. ...     print 2,i
  3. ...     
  4. 2 0
  5. 2 1
  6. 2 2
  7.  
though I didn't take it to 30.
Feb 9 '07 #17
The 2 in the example was just a reference to numbers in the twenties,ie
20
21
22
but I want them to print out with a space:
2 0
2 1
2 2
Feb 9 '07 #18
dshimer
136 Expert 100+
In the single digit numbers do you still need 2 numbers? For example...
0 0
0 1
0 2
Feb 9 '07 #19
dshimer
136 Expert 100+
Just in case, this may not be pretty because I have one foot out the door, but.
Expand|Select|Wrap|Line Numbers
  1. >>> for i in range(15):
  2. ...     num='%02d'%i
  3. ...     print num[0],num[1]
  4. 0 0
  5. 0 1
  6. 0 2
  7. 0 3
  8. 0 4
  9. 0 5
  10. 0 6
  11. 0 7
  12. 0 8
  13. 0 9
  14. 1 0
  15. 1 1
  16. 1 2
  17. 1 3
  18. 1 4
Feb 9 '07 #20
Not pretty?? I think it's beautiful ;) Thanks again to the both of you! I really appreciate your knowledge.
Feb 9 '07 #21
This is my last hang up with this......trying to get the app.exe to run with every number in range.

C:\python25>app.exe 0 0 1
C:\python25>app.exe 0 0 2

I guess I need to somehow loop the app.exe as well?
Feb 9 '07 #22
bartonc
6,596 Expert 4TB
This is my last hang up with this......trying to get the app.exe to run with every number in range.

C:\python25>app.exe 0 0 1
C:\python25>app.exe 0 0 2

I guess I need to somehow loop the app.exe as well?
I haven't read the docs so there may be a way to pass args to app.exe in the call. Also, I haven't really been following along too well and you haven't posted a lot of working code of your own. One possible way to do this might be:
Expand|Select|Wrap|Line Numbers
  1. cmd = 'c:/unix/find.exe %s %s' %(num[0], num[1])
  2. os.spawnv(os.P_WAIT, cmd, ['find', '/tmp'])
  3.  
Feb 10 '07 #23

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

Similar topics

3
by: Jean-Fran?ois Lacrampe | last post by:
Hello, I want to write a _very_ simple text parser that would replace a string like: "This is text with /italics/, *bold* and _underline_." and generate automatically something like this: ...
5
by: PM | last post by:
Has anyone found a way to open a file exclusively where it will fail if the file is already open, i have tried the following _FileStream = new FileStream(@"C:\Data.txt", FileMode.Open,...
14
by: D. Alvarado | last post by:
Hello, I am trying to open a window containing an image and I would like the image to be flush against the window -- i.e. have no padding or border. Can I make this happen with a single call to a...
3
by: Greg | last post by:
On my report I want to have an opening balance signifying all transactions up to the month selected and detailed transactions for the month selected and then a closing blance. I'm perpelexed...
11
by: emailus | last post by:
I am webmaster for the domain <www.alpha1.org.au>. Not being an expert in html, I take advantage of my domain Registrant's web building tool, 'Instant Website'. This tool is provided as part of...
9
compman9902
by: compman9902 | last post by:
Hello, and thank toy for reading this post. Thus far, this website has helped me a lot, (I have finally finished my encryptor: "site removed by moderator", go to the downloads link) and I will...
15
by: Umesh | last post by:
how to open a website like yahoo.com and use it as input? The following code doesn't work. #include"stdio.h" int main() { FILE *f; f=fopen("http://www.yahoo.com","r"); if(f==NULL)
3
by: Luke Davis | last post by:
I'm looking for an effective way to open and close TCP ports. Can I do this through Tcpclient? And I know this is a potential security risk, so what kind of permission must the person running...
34
by: Alexnb | last post by:
Gerhard Häring wrote: No, it didn't work, but it gave me some interesting feedback when I ran it in the shell. Heres what it told me: Traceback (most recent call last): File...
3
by: Paul H | last post by:
I have a transactions table and a balance table that look something like this: tblTransactions TransactionID (PK Autonumber) ClientID TransactionDate TransactionAmount (currency field, values...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.