Got piping working by fixing Read() handling to use 0 rather than -1 as the EOF output.

Also implemented a debug logging utility