title: Executing sudo command with space through python
body: <p>Hi guys and gal's I have a problem. </p>
  
  <p>I'm executing a python script that needs to run a sudo command to continue. This is the command:</p>
  
  <pre><code>sudo /etc/init.d/test restart
  </code></pre>
  
  <p>The issue is that no matter how I execute this it only runs sudo and /etc/init.d/test and returns:</p>
  
  <pre><code>sudo: /etc/init.d/test: command not found
  </code></pre>
  
  <p>The issue seems to be that restart is not sent along with the command.</p>
  
  <p>These are the ways I've tried running the command:</p>
  
  <p>Attempt 1 using os </p>
  
  <pre><code>os.system('sudo /etc/init.d/test restart')
  </code></pre>
  
  <p>Attempt 2 using subprocess</p>
  
  <pre><code>x = subprocess.Popen(['sudo','/etc/init.d/test','restart'])
  x.communicate()
  </code></pre>
  
  <p>Attempt 3 using subprocess again</p>
  
  <pre><code>x = subprocess.Popen(['sudo','/etc/init.d/test restart'])
  x.communicate()
  </code></pre>
  
  <p>This actually returned:</p>
  
  <pre><code>sudo: /etc/init.d/test restart: command not found
  </code></pre>
  
  <p>Which doesn't make sense since if I execute the command directly on the system it works.<br>
  Any ideas as to how I could do this?</p>