Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Apr 13th, 2005, 11:37 PM   #1
Azratax
Newbie
 
Join Date: Apr 2005
Posts: 3
Rep Power: 0 Azratax is on a distinguished road
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
Azratax is offline   Reply With Quote
Old Apr 14th, 2005, 6:25 AM   #2
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Location: Waterloo, Ontario
Posts: 1,888
Rep Power: 5 Sane will become famous soon enough
Send a message via MSN to Sane
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. :\
Sane is offline   Reply With Quote
Old Apr 14th, 2005, 9:15 AM   #3
Moldz
Programmer
 
Moldz's Avatar
 
Join Date: Feb 2005
Posts: 54
Rep Power: 4 Moldz is on a distinguished road
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.
Moldz is offline   Reply With Quote
Old Apr 14th, 2005, 1:27 PM   #4
Azratax
Newbie
 
Join Date: Apr 2005
Posts: 3
Rep Power: 0 Azratax is on a distinguished road
Thanks
Quote:
Originally Posted by Moldz
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.
This was what i was thinking of... Can this be done without source code of the program i want to control?
Thanks
Azratax is offline   Reply With Quote
Old Apr 14th, 2005, 2:17 PM   #5
Moldz
Programmer
 
Moldz's Avatar
 
Join Date: Feb 2005
Posts: 54
Rep Power: 4 Moldz is on a distinguished road
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.
Moldz is offline   Reply With Quote
Old Apr 14th, 2005, 3:39 PM   #6
Azratax
Newbie
 
Join Date: Apr 2005
Posts: 3
Rep Power: 0 Azratax is on a distinguished road
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
Azratax is offline   Reply With Quote
Old Apr 14th, 2005, 10:09 PM   #7
acab
Newbie
 
Join Date: Apr 2005
Posts: 7
Rep Power: 0 acab is on a distinguished road
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
acab is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 5:28 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC