Use subprocess to send a password Use subprocess to send a password python python

Use subprocess to send a password


Try

proc.stdin.write('yourPassword\n')proc.stdin.flush()

That should work.

What you describe sounds like stdin=None where the child process inherits the stdin of the parent (your Python program).


Perhaps you should use an expect-like library instead?

For instance Pexpect (example). There are other, similar python libraries as well.


from subprocess import Popen, PIPEproc = Popen(['sftp','user@server', 'stop'], stdin=PIPE)proc.communicate(input='password')

Try with input=‘password’ in communicate, that worked for me.