Reduce code duplication.
It's stdout, not stdin.
Arguments should be the other way around.