I'm doing a Python script where I need to spawn several ssh-copy-id processes, and they need for me to type in a password, so i'm using PExpect.
I have basically this:
child = pexpect.spawn('command')
child.expect('password:')
child.sendline('the password')
and then I want to spawn another process, I don't care about this one anymore, whether it ended or not.
child = pexpect.spawn('command2')
child.expect('password:')
child.sendline('the password')
And the code is hanging at the second "spawn"
However, if I comment out the first call, the second one works, so i'm guessing that the fact that the first one is still running or something is keeping it from working.
Now, the other thing I haven't been able to do is wait until the first one stops.
I've tried:
child.close() - it hangs (both with True and False as parameters)
child.read(-1) - it hangs
child.expect(pexpect.EOF) - it hangs.
child.terminate() - it hangs (both with True and False as parameters)
Any ideas on what could be happening?
NOTE: I'm not a Python expert, and i have never used pexpect before, so ANY idea is more than welcome.
Thanks!
UPDATE: This is definitely related to ssh-copy-id, because with other processes, spawn works well even if they don't return. Also, apparently ssh-copy-id never returns an EOF.