[comp.lang.pascal] output redirection

jamesp@world.std.com (james M peterson) (11/11/90)

The filename 'output' is the default output file.  It defaults to dos'
standard output file when you are not using the CRT unit.  The CRT unit
assigns output the a direct memory mapper.

YOU can also re-assign the output file to change where the output goes.

Try this:   program test;
begin
  writeln('Line one of output.');        { display on screen }

  assign(output,'out.put');              { assign output to file: out.put }
  rewrite(output);                       { zap existing and open of writing to}

  writeln('Line two of output.');        { ends up in out.put }

  close(output);                         { close it (do flush, etc too) }
  assign(output,'');                     { back to default output mode }
  rewrite(output);                       { zap & open for writing to }

  writeln('Line three of output.');      { display on screen }
end.

Try replacing 'out.put' with say 'lpt1' and gee it goes to the printer.
For a robust system, you need to add error checking, etc.

A general function can be made that:  closes current output and
opens new output.  Like  new_output(new_name:string12):boolean,
where new_name is the new name of the output file and the func
returns a true for success or false for failure.

Add ERROR TRAPPING!!!!!

jamesp@world.std.com