title: python - execute command and get output
body: <p>I need to build a server that can execute a command line command and send back the output of the command</p>
  
  <p><strong>Example:</strong></p>
  
  <p>for the command- echo hello world, the server will return the string "hello world".  </p>
  
  <p>I tried to use <code>subprocess.call()</code> function but it returns a number and not a string. I have the sever ready, i just need this this.  </p>
  
  <p><strong>Code:</strong></p>
  
  <pre><code>type=struct.pack("B",2) #packing type
  data=subprocess.call(client_data, shell=True)
  length=struct.pack("H",len(data)) #packing lenght
  client_soc.send(type+length+data)
  </code></pre>