StdoutCapture: Fix duplicated (and buggy) code.