Use the SPOOL command.