title: How to pass a variable to subprocess communicate
body: <p>I am new to python and have done several searches on SO and google regarding this question. </p>
  
  <p>How can I pass a variable pw, which is the user's password, to the input for popen.communicate?</p>
  
  <p>Here is the code involved:</p>
  
  <pre><code>pw = getpass.getpass()
  from subprocess import Popen, PIPE, STDOUT
              ssh_conn = Popen(["ssh", "-t", server, "sudo -S cp /etc/"+map, "/etc/"+map + "." +fulltime], stdout=PIPE, stdin=PIPE, stderr=STDOUT)
              ssh_conn.communicate(input='pw\n')[0]
  </code></pre>
  
  <p>The code above appears to send the string 'pw' to standard input, instead I would like the value of the variable pw to be sent. </p>
  
  <p>I realize that this approach is less than ideal and that there are other python modules that could do the job more simply, but I am not in a position to install any additional modules. </p>