Implement redirection from standard output

Fixed redirecting from standard output so that it works. This also
contains part of the fix for standard input.