Reputation: 3047
I develop a python gui for a c program. The Program asks for two passwords. How can I wait for the password promt and then insert the password in code?
At the moment I try to do this via:
subprocess.popen.communicate(input)
But that doesn't work as the program asks for the password in the shell again.
Just for your understanding here is the flow of the program:
Upvotes: 2
Views: 3310
Reputation: 1484
You should considerate using another library : Pexpect
Pexpect is a pure Python module for spawning child applications; controlling them; and responding to expected patterns in their output. Pexpect works like Don Libes’ Expect. Pexpect allows your script to spawn a child application and control it as if a human were typing commands.
Here is a sample of code to give a username and password when connecting to FTP server :
import pexpect
child = pexpect.spawn('ftp ftp.openbsd.org')
child.expect('Name .*: ')
child.sendline('bob')
child.expect('Password:')
child.sendline('thisisnotasecurepassword')
Upvotes: 2