![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Apr 2005
Posts: 3
Rep Power: 0
![]() |
How to have python control other program?
I have a program that runs through a console window. I want to control it (issue commands, respond to what is shown, etc) using a python script. Although i know how to do almost everything else that i will need for this within python (i have made simple scripts in python before, but nothing big), I dont know how to interface with this outside program. How does one do this? Im sure its painfully easy :-P
I also need to be able to tell python to "wait x seconds" before continuing to do stuff. How do i tell python to do this? Thanks -Az |
|
|
|
|
|
#2 |
|
Programming Guru
![]() |
import time
time.sleep(x) #where x equals the amount of time in seconds to delay, can be float or integer. Sorry, I haven't done any programming for outside response. I'm sure someone here can help though. :\ |
|
|
|
|
|
#3 |
|
Programmer
Join Date: Feb 2005
Posts: 54
Rep Power: 4
![]() |
Usually interfacing with an outside program requires some form of interprocess communication (IPC), such as signals, pipes, sockets, etc. But the program running in the console would need to already have these communication abilities. Do you have the source code to change it?
There might be an easier way. If you can redirect the the output, error, and input stream to your python script, you can have it read from the console program and respond to it. |
|
|
|
|
|
#4 | |
|
Newbie
Join Date: Apr 2005
Posts: 3
Rep Power: 0
![]() |
Thanks
Quote:
Thanks |
|
|
|
|
|
|
#5 |
|
Programmer
Join Date: Feb 2005
Posts: 54
Rep Power: 4
![]() |
I think you could, but the proof is in the trying. For example, in a Unix shell, you could try to redirect stdout, stdin, and stderr to your python program then control it from there.
|
|
|
|
|
|
#6 |
|
Newbie
Join Date: Apr 2005
Posts: 3
Rep Power: 0
![]() |
This is going to be done in windows. The thing is, i've never done anything remotely like this in programming. So i would have NO idea where to start on these things....
How might i go about this? Where could i find resources on this? I dont even know what to google for to get info on this. Thanks |
|
|
|
|
|
#7 |
|
Newbie
Join Date: Apr 2005
Posts: 7
Rep Power: 0
![]() |
Hi Azratax, it sounds like we're looking for the same thing, so I thought before I post a similar message I would add a little to yours, I hope your cool with that.
I'm looking to create a python script that executes dos promt commands which launch another program that runs out of the dos shell, then run commands on that program. hscript file.hip #is the first command, now were in hscript, not dos cd /obj/model1 # is the second command, this looks like unix but is hscript opparm -d sphere1 tx # is the third command output the result of the third command to a file. Is seems like it should be very simple, but I am new to scripting and need a little guidence, I saw a similar script in Perl which looked something like: command HSCRIPT filename command HSCRIPT cd /obj/model1 and so on... Thank you in advance to anyone who can help ac |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|