 <p>Or try to use the <strong>python-pexpect</strong> package instead of <strong>Subprocess</strong>. Much easier and friendly.</p> <pre><code>import pexpect mypassword='somepassword' child = pexpect.run('passwd guille') child.expect('Password:') child.sendline(mypassword) </code></pre>