Must write to ouput before trying to read input