Added fflush() calls to ensure the prompt is displayed if stderr is being piped