I am making a Python script where I need to call several ssh-copy-id processes and they need to enter a password, so I use PExpect.
I basically have this:
child = pexpect.spawn('command') child.expect('password:') child.sendline('the password')
and then I want to create another process, I no longer care about it whether it is finished or not.
child = pexpect.spawn('command2') child.expect('password:') child.sendline('the password')
And the code hangs on the second "spawn"
However, if I comment on the first call, the second works, so I assume that the fact that the first one is still working or something does not allow it to work.
Now, another thing that I could not do is wait until the first one stops. I tried:
child.close () - it hangs (both with True and False parameters as parameters) child.read (-1) - it hangs
child.expect (pexpect.EOF) - it hangs.
child.terminate () - it hangs (both with True and False parameters as parameters)
Any ideas on what could happen?
NOTE. I am 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 spawn works well with other processes, even if they don't return. In addition, it is obvious that ssh-copy-id never returns EOF.
python process pexpect
Daniel Magliola
source share