2

I need functionality similar to the Unix expect from within a Python script, as an external executable is prompting for password. I am currently doing this:

p = subprocess.Popen("execA",stdout=subprocess.PIPE,stderr=subprocess.STDOUT)

where execA is prompting for password. I'd like to wrap it with "expect" to supply said password.

There seem to be a few alternatives:

Pexpect - Noah Spurrier

Python Expect

What is the best way to do this? If there's a more efficient way to go about it, I'd love to know.

1
  • 2
    Try not to ask for "preferences" (asking for opinions is against the FAQ) but experience. Commented Aug 9, 2011 at 7:38

2 Answers 2

1

Pexpect is the one I've used in the past to do things like this.

Though depending on the program it might be sufficient to just write to it's stdin?

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

1 Comment

Thanks for your help, pexpect is what I used, but I also learnt that for kerberos integrated passwords a keytab file maybe a better option. Writing to stdin does not work if the password prompt is displayed after some processing. hope this helps others as well.
0

Those kind of programs typically access the tty directly and put it in "raw" mode. So the stdio pipes don't work. You need to spawn the subprocess in a pty. A simple read/write with that might work. Those "expect-like" modules are usually for more complex scenarios.

Of course I prefer this one, but I'm not sure it will work on OSX.

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.