Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Auto respond to script prompts

Status
Not open for further replies.

natefish

Technical User
Sep 1, 2006
3
0
0
US
I am using python 2.0 (due to limitations setting by the system I am working on) and have to routinely run a series of scripts that require the same user input over and over again.

Is there a way to create another script to automatically fill out these prompts? I cannot edit the original scripts in any way.

Thanks,
nf
 
Is this on a Unix or Linux machine? Or a Windows?
 
This is on a Windows XP Pro SP2 machine.
 
if the authors of the original scripts used constructs such as
Code:
if __name__ == '__main__'
then you could perhaps write a small python script that imported the original scripts
e.g.,
Code:
# original_script1.py
def sayhi(user, passwd):
    print 'Hello', user

if __name__ == '__main__':
    user = raw_input('name:')
    passwd = raw_input('passwd:')
    sayhi(user, passwd)
then we could write
Code:
# new_script.py
import original_script1

if __name__ == '__main__':
    user = 'justin'
    passwd = 'foobar'
    original_script1.sayhi(user, passwd)
 
thanks for the suggestion, however this method doesn't work in this instance because (I discovered as I looked at the source code more closely) the main script calls other scripts which call other scripts etc. It looks like a pretty big mess to try and sort out which scripts require which input...

any other ideas?

nf
 
given the following script (Script1.py) which asks for two inputs

Code:
import time

def hi(a): print 'hi', a

def hello(b): print 'hello', b

if __name__ == '__main__':
    x = raw_input('hi: ')
    hi(x)
    time.sleep(5)
    y = raw_input('hello: ')
    hello(y)

and the following file (input.txt)

Code:
foo
bar

I can, from the console, issue the following

Code:
type input.txt | python Script1.py

or you could look at os.popen* or the popen2 module
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top