extended to work with stdout and stderr