0

I downloaded some scripts in both python and bash that prompt the user for command line input. Since I run these scripts often, I would like to automatically supply the input to the programs. I prefer not to modify the scripts. Is there a way to do it without modifying the original code?

[UPDATE] thanks to EnabrenTane's advice, it seems to work pretty well, until I got to a line that read password = getpass.getpass('password: '). It complains the following:

File "/usr/lib/python2.4/getpass.py", line 29, in unix_getpass
old = termios.tcgetattr(fd)     # a copy to save
termios.error: (25, 'Inappropriate ioctl for device')

Any way to get around that?

3

3 Answers 3

3

Like this on bash: $ ./python_script < input.txt

edit: Alternatively you could write your scripts to take ARGV as a file name to read from. You could reopen STDIN to the file and not have to change any other lines.

Sign up to request clarification or add additional context in comments.

Comments

1

Since the responses in via stdin:

cat answers | yourscript.py

Comments

1

Due to the password requirement, I ended up using pexpect, a python module that automates user input.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.