Programming Forums
User Name Password Register
 

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

Reply
 
Thread Tools Display Modes
Old Apr 17th, 2005, 4:18 PM   #1
acab
Newbie
 
Join Date: Apr 2005
Posts: 7
Rep Power: 0 acab is on a distinguished road
how to send commands to a prompt?

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. If someone could point me to the best mods to investigate and some example code or tutorials I'd be so greatful.

The following are a few esential commands I'm wanting to execute at the prompt:

#1. hscript file.hip #is the first command, this launches hscript and loads the file.hip as the current scene, hscript is a non gui version of a 3d ap. *.hip is a scene file we're now inside of.

#2 cd /obj/model1 #is the second command, this looks like unix but is hscript (similar to unix) and takes me into a 3d object within the *.hip scene file.

#3 opparm -d sphere1 tx #is the third command, this reads the parameter value for translation X for the sphere object.

Finaly to 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.

Thank you in advance to anyone who can help
acab
acab is offline   Reply With Quote
Old Apr 18th, 2005, 8:46 AM   #2
Moldz
Programmer
 
Moldz's Avatar
 
Join Date: Feb 2005
Posts: 54
Rep Power: 4 Moldz is on a distinguished road
Not sure if this is what you are looking for, but check out the docs on process management, especially exec or spawn for running new programs.
Moldz is offline   Reply With Quote
Old Apr 20th, 2005, 6:13 PM   #3
acab
Newbie
 
Join Date: Apr 2005
Posts: 7
Rep Power: 0 acab is on a distinguished road
Thank you Moldz for the tip, but its still not to clear, I find that often times tech notes make little sense in the beggining when I'm first learning something and over time they make more and more sense.
So, if anyone could give me an example of how process managment could help...
I need examples...

thanx
acab
acab is offline   Reply With Quote
Old Apr 20th, 2005, 8:48 PM   #4
Moldz
Programmer
 
Moldz's Avatar
 
Join Date: Feb 2005
Posts: 54
Rep Power: 4 Moldz is on a distinguished road
Ok, I was intrigued enough to dig a little deeper. You need to check out the popen2 module.

It allows you to start a program and get a reference to its input and output. It's really easy to read the output of a program and really easy to send input to a program, but really tricky to do both. Try something like this:
import popen2

# you may need to use the absolute path
# for the command and notice that it is
# sending the output to a file named
# "out.txt"
cmd = "hscript file.hip > out.txt"  
fromchild, tochild = popen2.popen2(cmd)
fromchild.close()

# don't forget newlines after the commands
tochild.write("cd /obj/model1\n")   
tochild.flush()
tochild.write("opparm -d sphere1 tx\n")
tochild.flush()

tochild.close()
You could then use python to open the output file, "out.txt", and pull out the parts you need.
Moldz is offline   Reply With Quote
Old Apr 28th, 2005, 5:20 AM   #5
acab
Newbie
 
Join Date: Apr 2005
Posts: 7
Rep Power: 0 acab is on a distinguished road
Hey Moldz, you rock... That gets me so close. Though right now I've decided to focus on learning the basics, that why its taken me so long to reply to your latest post, I just haven't seen it tell now. But even now I don't entirely understand your example code which tells me that I'm doing the right thing by focusing on the basics. Once I'm a little more familiar with Python and programing in general I'll be back.

Thanks again
acab
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 8:20 PM.

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