I’m spawning an ssh process in my python script like this:
env = {'SSH_ASKPASS':'/home/max/repo/vssh/vssh/vssh.py', 'DISPLAY':':123'}
for x in sessions:
current_session = Popen(["ssh", x.address],
stdin=PIPE,
stdout=PIPE,
stderr=None,
shell=False,
env=env,
preexec_fn=os.setsid)
The problem is my script starts the subprocess, then keeps on going. ssh requires a password to be given to it, which is what I’m trying to redirect to the STDOUT/STDIN of my script. Except that by the time it asks for my password, my script is done.
How can I make my script stop until I enter the password and successfully set up a connection via ssh?
If it’s really reading from stdin, then you can use the communicate method. But password prompts often bypass stdin and communicate with the controlling terminal, in which case you need something like pexpect.
You might want to look into SSH modules for Python, which should be simpler and more robust than managing a subprocess.