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
22 3426
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: -
try:
-
### Read registry for InstaCal path
-
instacalKey = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE,
-
"SOFTWARE\Universal Library")
-
self.pmdPath = str(_winreg.QueryValueEx(instacalKey, 'RootDirs')[0])
-
instacalKey.Close()
-
except WindowsError:
-
self.InstaCalBtn.Disable()
-
self.pmdPath = ""
then: -
-
def OnInstaCalButton(self, event):
-
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.
Thank you for the reply. I know the path of the exe. Could I do something like this: -
import os, sys
-
-
pyPath = "C:\python25\app.exe"
-
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. -
MaxR = -1.0;
-
for(i=1; i<1000; i++){
-
... code
-
-
system(sRun);
-
-
....code
-
-
R = ... the elapsed time of the function system().
-
if (R > MaxR){
-
MaxR = R;
-
MaxI = i;
-
}
-
}
-
-
printf ("Max(i) = %d elapsed %.9f secs \n", MaxI, MaxR);
-
ex: system("app.exe1 1 1 1") was used to call the application. Does python have something similar?
Thank you for the reply. I know the path of the exe. Could I do something like this: -
import os, sys
-
-
pyPath = "C:\python25\app.exe"
-
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". -
import os, sys
-
appPath = r"C:\python25\app.exe"
-
# or
-
appPath = u"C:\python25\app.exe"
-
I prefer raw strings. Boa Construtor uses unicode strings.
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. -
MaxR = -1.0;
-
for(i=1; i<1000; i++){
-
... code
-
-
system(sRun);
-
-
....code
-
-
R = ... the elapsed time of the function system().
-
if (R > MaxR){
-
MaxR = R;
-
MaxI = i;
-
}
-
}
-
-
printf ("Max(i) = %d elapsed %.9f secs \n", MaxI, MaxR);
-
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: - from time import time
-
startTime = time()
-
for i in xrange(1000):
-
# simulate an external process
-
for i in range(10000):
-
pass
-
-
print "Process took %f seconds" % (time() - startTime)
There is a discussion on the timeit module here.
There are a few ways to do this: - from time import time
-
startTime = time()
-
for i in xrange(1000):
-
# simulate an external process
-
for i in range(10000):
-
pass
-
-
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.
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
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: -
from time import time
-
startTime = time()
-
for i in xrange(1000):
-
# simulate an external process
-
for i in range(1000):
-
pass
-
-
print "Process took %f seconds" % (time() - startTime)
-
This will run the app.exe
Code: -
import subprocess
-
-
subprocess.Popen(r"C:\python25\app.exe")
-
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: -
import os,sys
-
-
pyPath=r"C:\python25\python.exe"
-
appPath=r"C:\python25\app.exe"
-
os.spawnv(os.P_NOWAIT,pyPath,["python",appPath])
-
-
from time import time
-
startTime = time()
-
for i in xrange(1000):
-
# simulate an external process
-
for i in range(10000):
-
pass
-
-
print "Process took %f seconds" % (time() - startTime)
-
-
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.
-
import os,sys
-
-
pyPath=r"C:\python25\python.exe"
-
appPath=r"C:\python25\app.exe"
-
os.spawnv(os.P_NOWAIT,pyPath,["python",appPath])
-
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.
-
import os,sys
-
-
pyPath=r"C:\python25\python.exe"
-
appPath=r"C:\python25\app.exe"
-
os.spawnv(os.P_NOWAIT,pyPath,["python",appPath])
-
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.
Should have put this in before, but for example to run the find command on my /tmp directory and time it - >>> def test():
-
... start=time.time()
-
... os.spawnv(os.P_WAIT,'c:/unix/find.exe',['find','/tmp'])
-
... print time.time()-start
-
...
-
>>> test()
-
0.950999975204
-
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.
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
Thank you both for your replies! One more thing.....how could I do this: -
i = 0
-
for i in range(0,30):
-
print i
-
i +=1
-
....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?
Thank you both for your replies! One more thing.....how could I do this: -
i = 0
-
for i in range(0,30):
-
print i
-
i +=1
-
....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?
-
I don't see where the "2" is coming from in your example.
-
Print will put a space in for you by using the comma.
-
range() takes (start, [stop], [step]) where braces mean optional parameters.
-
for i in range(30):
-
print 2, i
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
a start of 0 is implied, though if you need to reset it you can just say
range is just creating a list of numbers, each member of which gets evaluated as i during the loop. - >>> range(5)
-
[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 - >>> for i in range(3):
-
... print 2,i
-
...
-
2 0
-
2 1
-
2 2
-
though I didn't take it to 30.
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
In the single digit numbers do you still need 2 numbers? For example...
0 0
0 1
0 2
Just in case, this may not be pretty because I have one foot out the door, but. - >>> for i in range(15):
-
... num='%02d'%i
-
... print num[0],num[1]
-
0 0
-
0 1
-
0 2
-
0 3
-
0 4
-
0 5
-
0 6
-
0 7
-
0 8
-
0 9
-
1 0
-
1 1
-
1 2
-
1 3
-
1 4
Not pretty?? I think it's beautiful ;) Thanks again to the both of you! I really appreciate your knowledge.
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?
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: - cmd = 'c:/unix/find.exe %s %s' %(num[0], num[1])
-
os.spawnv(os.P_WAIT, cmd, ['find', '/tmp'])
-
Sign in to post your reply or Sign up for a free account.
Similar topics
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:
...
|
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,...
|
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...
|
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...
|
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...
|
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...
|
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)
|
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...
|
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...
|
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...
|
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
|
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...
|
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,...
|
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...
|
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,...
|
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...
|
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...
|
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,...
|
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...
| |