title: Using python to open cmd and automatically enter a password
body: <p>I've managed to get the cmd being opened by python. However, using runas administrator comes with a password check before cmd.exe is executed.</p>
  
  <p>I'm using this to open cmd...</p>
  
  <p><code>import subprocess</code></p>
  
  <p><code>subprocess.call(["runas", "/user:Administrator", "cmd.exe"])</code></p>
  
  <p>I'm looking for a way to automatically enter the password into the runas.exe prompt which opens when i run the code. Say if i were to create <code>var = "test"</code> and add it after <code>import subprocess</code> how would i make it so that this variable is passed to and seen as an input to the runas.exe?</p>
  
  <p>The solution would require only python modules which are in version 3.4 or higher.</p>
  
  <hr>
  
  <h2>Update</h2>
  
  <p>I have found some code which appears to input straight into runas.exe. However, the apparent input is <code>\x00\r\n</code> when in the code the input is supposed to be <code>test</code> I am fairly certain that if i can get the input to be <code>test</code> then the code will be successful.</p>
  
  <p>The code is as follows :  </p>
  
  <pre><code>import subprocess
  
  args = ['runas', '/user:Administrator', 'cmd.exe']
  
  proc = subprocess.Popen(args, 
                          stdin=subprocess.PIPE, 
                          stdout=subprocess.PIPE, 
                          stderr=subprocess.PIPE)
  
  proc.stdin.write(b'test\n')
  proc.stdin.flush()
  
  stdout, stderr = proc.communicate()
  print (stdout)
  print (stderr)
  </code></pre>