title: Python: Give input for a subprocess
body: <p>I have to create a new process with Admin privileges using a python script. I searched on the Internet about this topic and found out that I have to use <code>runas</code> command. For this command, I have to give an user and at runtime, the script will wait for the password and I want to do this as automatic as possible.</p>
  
  <p>This is my code:</p>
  
  <pre><code>import subprocess
  
  p = subprocess.Popen(['runas', '/user:Armando', szCmdCommand], stdin = subprocess.PIPE)
  p.stdin.write('password')
  </code></pre>
  
  <p>Instead of <code>.write</code> I tried <code>p.communicate(input='password')</code> but it isn't working because it doesnt write the password. The only thing that happens is that the script doesn't wait for input. It automatically takes a wrong password and fails the execution of my command.</p>
  
  <p>What can I do to fix this?</p>