Restructure execution of commands

* Do not use poll.wait() as it will block if there is excessive output
* Collect stdout and stderr
* Treat any non-zero returncode as an error

Signed-off-by: Simon Horman <horms@verge.net.au>
Update error handling of select loop

* Always call proc.kill()
* Call proc.wait()
* Do not call proc.communicate(): It may wait a very long time (forever?)

Signed-off-by: Simon Horman <horms@verge.net.au>