Fixed bugs and tidied code.
New class to run a command in the foreground, and process the stdout and stderr output streams.