title: running a command as a super user from a python script
body: <p>So I'm trying to get a process to be run as a super user from within a python script using subprocess.  In the ipython shell something like</p>
  <pre><code>proc = subprocess.Popen('sudo apach2ctl restart',
                          shell=True, stdin=subprocess.PIPE,
                          stdout=subprocess.PIPE,
                          stderr=subprocess.PIPE)
  </code></pre>
  <p>works fine, but as soon as I stick it into a script I start getting: <code>sudo: apach2ctl: command not found</code>.</p>
  <p>I would guess this is due to the way sudo handles environments on ubuntu. (I've also tried <code>sudo -E apche2ctl restart</code> and <code>sudo env path=$PATH apache2ctl restart</code> with no avail)</p>
  <p>So my question is basically, if I want to run <code>apache2ctl restart</code> as super user that prompts the user for the super user password when required, how should I go about doing this?  I have no intention of storing passwords in the script.</p>
  <p>Edit:</p>
  <p>I've tried passing in the commands as both a string and tokenized into a list.  In the python interpreter, with a string I'll get the password prompt properly (still doesnt work in a python script as in my original problem), a list just gives the help screen for sudo.</p>
  <p>Edit 2:</p>
  <p>So what I gather is that while Popen will work with some commands just as strings when shell=True, it takes</p>
  <pre><code>proc = subprocess.Popen(['sudo','/usr/sbin/apache2ctl','restart'])
  </code></pre>
  <p>without 'shell=True' to get sudo to work.</p>
  <p>Thanks!</p>