Reputation: 137
we can't redirect the output inside the DELPHI IDE for an command line application to e.g. to a file.
We know how to do this using Pycharm IDE but did not find a solution using Delphi
Is there any other solution with Delphi IDE existing ?
Delphi 10.3 RIO Community Version used
Upvotes: 3
Views: 373
Reputation: 34889
Not within the IDE, but from code it is possible.
In your console program, insert these lines at the top of the program:
AssignFile(Output,'MyOutputFile.txt');
Rewrite(Output);
This will redirect the standard output handler to a text file.
Example that outputs the text into a file only in debug mode:
program TestFileOutput;
{$APPTYPE CONSOLE}
begin
{$IFDEF debug} // Output to text file only in debug mode
AssignFile(Output,'MyOutputFile.txt');
Rewrite(Output);
{$ENDIF}
WriteLn('Hello Delphi');
end.
Upvotes: 5