Title: getpass.getpass() does not accept stdin from an Expect script
Type: Stage:
Components: Library (Lib) Versions:
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: brent saner, terry.reedy
Priority: normal Keywords:

Created on 2017-05-14 04:05 by brent saner, last changed 2017-05-19 19:16 by terry.reedy.

File name Uploaded Description Edit
expect-getpass.poc.tar brent saner, 2017-05-14 04:05 Tarball of two very simple scripts used for proof of behaviour described
expect-getpass2.poc.tar brent saner, 2017-05-14 04:15 Tarball of two very simple scripts used for proof of behaviour described (2.x)
Messages (4)
msg293630 - (view) Author: brent saner (brent saner) Date: 2017-05-14 04:05
This is reproducible on both 2.7.13 and 3.6.1.

Please refer to the attached files for demonstration. It seems that when I spawn a python script using getpass.getpass() from expect ( - I'm using version 5.45), the input is not passed. Further, it seems interactive control is handed over to the shell- however, it doesn't actually pass anything to the python script that was spawned, forcing one to break out of the expect process itself.

Obviously, the proofs attached require the expect binary to be installed. To test, simply mark "poc.exp" as executable and execute it (assuming is in the same directory. If not, you'll need to edit line 4 of poc.exp).
msg293631 - (view) Author: brent saner (brent saner) Date: 2017-05-14 04:15
NOTE: the example scripts given are for py3k, obviously. these should work (or rather, "not work") for 2.

of course, you'll also have to mark the as executable as well for both.
msg293649 - (view) Author: brent saner (brent saner) Date: 2017-05-14 15:14
i have found a workaround- it seems that if i add a "sleep 2" in the expect script before and after the getpass() entry prompt points, it works. which doesn't make sense to me, considering the getpass() prompt seems to take just as long as the other prompts to render, but who knows.

i'm not sure if this is an invalid bug or not, i'd welcome ideas as to which it'd be. if invalid, feel free to close.
msg293966 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2017-05-19 19:16
I strongly suspect that this should be closed as 'not a bug', but I know too little about expect to be sure.  If there is a python, as opposed to expect or os bug, then it should be possible to demonstrate the problem with python.  If you leave this open, please post to python-ideas, where there are people who use expect.

Also, text files should be uploaded as they are, uncompressed, so readers can click and view in a browser.
Date User Action Args
2017-05-19 19:16:26terry.reedysetnosy: + terry.reedy
messages: + msg293966
2017-05-14 18:26:09josh.rsettitle: getpass.getpass() does not except stdin from an Expect script -> getpass.getpass() does not accept stdin from an Expect script
2017-05-14 15:14:37brent sanersetmessages: + msg293649
2017-05-14 04:15:59brent sanersetfiles: + expect-getpass2.poc.tar

messages: + msg293631
2017-05-14 04:05:40brent sanercreate