The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> Python Programming
|
python in windows
Discuss python in windows in the Python Programming forum on Dev Shed. python in windows Python Programming forum discussing coding techniques, tips and tricks, and Zope related information. Python was designed from the ground up to be a completely object-oriented programming language.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

June 6th, 2004, 11:25 PM
|
|
Registered User
|
|
Join Date: Apr 2004
Posts: 5
Time spent in forums: 18 m 21 sec
Reputation Power: 0
|
|
|
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.
|

June 7th, 2004, 04:44 AM
|
 |
(retired)
|
|
Join Date: Dec 2003
Location: The Laboratory
|
|
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
|

June 7th, 2004, 05:50 AM
|
 |
Hello World :)
|
|
Join Date: Mar 2003
Location: Hull, UK
|
|
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.
__________________
programming language development: www.netytan.com – Hula
|

June 7th, 2004, 06:03 AM
|
|
Contributing User
|
|
Join Date: Feb 2004
Location: London, England
|
|
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.
|

June 7th, 2004, 06:06 AM
|
|
Contributing User
|
|
Join Date: Feb 2004
Location: London, England
|
|
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
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|