title: Python - subprocess.Popen - ssh -t user@host 'service --status-all'
body: <p>I've read a bunch of examples but none of them work for this specific task.</p>
  
  <p>Python code:</p>
  
  <pre><code>x = Popen(commands, stdout=PIPE, stderr=PIPE, shell=True)
  print commands
  stdout = x.stdout.read()
  stderr = x.stderr.read()
  print stdout, stderr
  return stdout
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>[user@host]$ python helpers.py
  ['ssh', '-t', 'user@host', ' ', "'service --status-all'"]
   usage: ssh [-1246AaCfgKkMNnqsTtVvXxYy] [-b bind_address] [-c cipher_spec]
             [-D [bind_address:]port] [-e escape_char] [-F configfile]
             [-I pkcs11] [-i identity_file]
             [-L [bind_address:]port:host:hostport]
             [-l login_name] [-m mac_spec] [-O ctl_cmd] [-o option] [-p port]
             [-R [bind_address:]port:host:hostport] [-S ctl_path]
             [-W host:port] [-w local_tun[:remote_tun]]
             [user@]hostname [command]
  </code></pre>
  
  <p>Why am i getting this error?
  Using os.popen(...) it works, it executes at least but i can't retrieve the output of the remote command via the SSH tunnel.</p>