title: Python running ping and getting the exit code
body: <p>I am trying to ping a host via a python script, and capture both the output and the exit code of ping. for this I came up with the following python snippet:</p>
  
  <pre><code>ping_command = "ping -c 5 -n -W 4 " + IP
  ping_process = os.popen(ping_command)
  ping_output = ping_process.read()
  exit_code_ping = ping_process.close()
  exit_code = os.WEXITSTATUS(exit_code_ping)
  print ping_output
  print exit_code
  </code></pre>
  
  <p>and I have observed that if the host with the given IP is down or it's unreachable the code works. However if the host is up it gives me:</p>
  
  <pre><code>exit_code = os.WEXITSTATUS(exit_code_ping)
  TypeError: an integer is required
  </code></pre>
  
  <p>and since I'm pretty beginner in python I have no clue what the problem is here.</p>
  
  <p>Questions: What am I doing wrongly and why is this thing not working ... and most importantly, how can I make it work.</p>