title: Running sudo command via CGI (Python)
body: <p>I am writing a test suite for a web application using Selenium.</p>
  
  <p>In the course of which I need to test behaviour of the app in case a certain service is running or not.</p>
  
  <p>I wanted to create a cgi call to a Python script turning that service on and off.</p>
  
  <p>I know that the cgi call is in the context of the webserver (Apache) however thought that issuing sudo calls like so:</p>
  
  <pre><code>import subprocess
  import os
  command = 'sudo -S launchctl unload /Library/LaunchAgents/com.my.daemon.plist'
  pwd = 'pwd123'
  test1 = subprocess.Popen( command, shell=True, stdin=subprocess.PIPE)
  test1.communicate(input=pwd)
  test2 = os.system( 'echo %s|%s' % (pwd,command) )
  </code></pre>
  
  <p>would do the trick, well they don't I get return code 256.</p>
  
  <p>What can I do to have this call be executed w/o touching the context in which Apache runs?</p>
  
  <p>As for security: this will only run on a test machine.</p>