|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
python in windows
Hi all,
I have python 2.3.4 for windows installed. I am working on a project where i'm using GHS Multi-2000 s/w,a simulator for embedded processors. The code written has many test cases which have to be executed one by one manually.I have thought of automating these tests using python.I just want to "bypass" keyboard input and instead ,my script should take the inputs from a file "inputs.txt".Can anyone tell if it is possible in windows environment using python 2.3.4? I know that it can be easily done in linux. |
|
#2
|
||||
|
||||
|
Yep.
I'm not sure about piping commands in windows (which is how I'd do it under linux/bsd), but you can always do something like this: Code:
#!/usr/bin/python
import os
try: # try to open your input file
fhandle = open('inputs.txt', 'r')
data = fhandle.readlines()
fhandle.close()
except IOError: # abort!
print "Can't open file inputs.txt for reading!"
sys.exit(0)
for line in data:
os.system("ghs.exe %s" % (line)) # runs system command..
Cheers, Simon |
|
#3
|
||||
|
||||
|
What that work on one platform will in most cases work on others, which is some of the reasons people choose Python over other languages. As long as you stay away from platform spacific modules and commands you'll be fine!
To open a pipe from Python you need to use one of the os.popen() classes but they are very easy to use if you know how to use files in Python .Code:
#!/usr/bin/env python
import os
try:
for line in file('input.txt'): os.popen('runow.exe').write(line)
except IOError:
raise SystemExit
Note: this example, though untested, should be easy to addapt your needs. Hope this helps, Mark. |
|
#4
|
|||
|
|||
|
I'm not sure if this is what you mean, but you can redirect input to read from a file on the Windows command line just as you can in UNIX shells:
Code:
c:\> python myprog.py < input.txt so there may be no need to change the program at all. Dave - The Developers' Coach Last edited by DevCoach : June 7th, 2004 at 06:07 AM. |
|
#5
|
|||
|
|||
|
Oh, and piping works the same as in UNIX, too:
Code:
c:\> prog1 someparams | prog2 moreparams feeds the output from prog1 into the input to prog2. Dave - The Developers' Coach |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Python Programming > python in windows |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|