3

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 enter image description here

Is there any other solution with Delphi IDE existing ?

Delphi 10.3 RIO Community Version used

1 Answer 1

5

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.
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.