Fix stdout/err handling