A r t i c l e s
|
Redirecting STDOUT To Text File
|
Redirecting standard out on the command line to a text file is not so hard if you know about the OUTPUT global variable which you can take control of.
program project1;
{$mode objfpc}{$H+}
var
RedOutFile: text;
procedure RedirectSTDOUT(FileName: string);
begin
// close(OUTPUT); //closes STDOUT, actually doesn't seem to be needed.
Assign(OUTPUT, FileName); // now assign a file to STDOUT (redirect)
Rewrite(OUTPUT); // open file for writing
end;
procedure RestoreSTDOUT;
begin
close(output); // close file
Assign(output,''); // restore STDOUT mode
rewrite(output); // open STDOUT for writing
end;
begin
WriteLn('This text is written to console');
RedirectStdOut('Error.txt');
writeln('This text is written to Error.txt');
// want to restore std out?
RestoreStdOut;
WriteLn('Back to console again');
readln;
end.
|
|
About
This site is about programming and other things.
|