more precise stdout handling