Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Auto respond to script prompts

Auto respond to script prompts

Auto respond to script prompts

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.


RE: Auto respond to script prompts

Is this on a Unix or Linux machine? Or a Windows?

RE: Auto respond to script prompts

This is on a Windows XP Pro SP2 machine.

RE: Auto respond to script prompts

if the authors of the original scripts used constructs such as


if __name__ == '__main__'
then you could perhaps write a small python script that imported the original scripts


# 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


# new_script.py
import original_script1

if __name__ == '__main__':
    user = 'justin'
    passwd = 'foobar'
    original_script1.sayhi(user, passwd)

RE: Auto respond to script prompts

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?


RE: Auto respond to script prompts

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


import time

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

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

if __name__ == '__main__':
    x = raw_input('hi: ')
    y = raw_input('hello: ')

and the following file (input.txt)



I can, from the console, issue the following


type input.txt | python Script1.py

or you could look at os.popen* or the popen2 module

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close