wait_for_output utility function