title: Python script executes from terminal, but not when using subprocess?
body: <p>I'm using <code>subprocess</code> to execute a Python script called trace.py that is located in a different folder. The script trace.py then uses subprocess to run a traceroute command and then prints the output. When I go to the folder that trace.py is located in and type this in the terminal:</p>
  
  <pre><code>python trace.py
  </code></pre>
  
  <p>or</p>
  
  <pre><code>./trace.py
  </code></pre>
  
  <p>or from any location:</p>
  
  <pre><code>python /home/.../cgi-bin/trace.py
  </code></pre>
  
  <p>it works fine and the traceroute is printed to the terminal. However, when I try to execute trace.py from main.py by using <code>subprocess</code>, it doesn't seem to work. I've tested this by creating test.py and using subprocess to execute it from main.py and this works. I do this with the following:</p>
  
  <pre><code>output = subprocess.check_output([sys.executable, script_path])
  </code></pre>
  
  <p>Where <code>script_path</code> is the absolute path to <code>trace.py</code>.</p>
  
  <p>The full error I get is this (paths are shortened):</p>
  
  <pre><code>Traceback (most recent call last):
      File "/home/.../cgi-bin/trace.py", line 11, in &lt;module&gt;
  traceroute = subprocess.check_output(["traceroute", "www.google.com"])
      File "/usr/lib/python2.7/subprocess.py", line 566, in check_output
  process = Popen(stdout=PIPE, *popenargs, **kwargs)
      File "/usr/lib/python2.7/subprocess.py", line 710, in __init__
  errread, errwrite)
      File "/usr/lib/python2.7/subprocess.py", line 1327, in _execute_child
  raise child_exception
  OSError: [Errno 2] No such file or directory
  Traceback (most recent call last):
      File "main.py", line 97, in &lt;module&gt;
  serve(args.port, public_html, cgibin)
      File "main.py", line 55, in serve
  process = subprocess.check_output(["/usr/bin/python", script_path])
      File "/usr/lib/python2.7/subprocess.py", line 573, in check_output
  raise CalledProcessError(retcode, cmd, output=output)
  subprocess.CalledProcessError: Command '['/usr/bin/python', '/home/.../cgi-bin/trace.py']' returned non-zero exit status 1
  </code></pre>
  
  <p>Why does this not work, but executing it from the terminal does?</p>