Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2008-12

Forcing a text file to use a predefined handle

3 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Mark Morgan Lloyd

I can get a program compiled with Turbo Pascal to use the existing stderr handle for output like this:

PROGRAM Meta2(Input, Output, Error);
..
   Assign(Error, '');
   Rewrite(Error);
   TextRec(Error).Handle:= 2;

or in the case of Delphi:

program Meta2;
..
   Assign(Error, '');
   Rewrite(Error);
   TTextRec(Error).Handle:= GetStdHandle(STD_ERROR_HANDLE);

Is there a correct and portable way to do this using FPC?

Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]

Reply by email

Michael Van Canneyt
to Mark Morgan Lloyd
Mark Morgan Lloyd wrote 18 lines
I can get a program compiled with Turbo Pascal to use the existing stderr handle for output like this: PROGRAM Meta2(Input, Output, Error); .. Assign(Error, ''); Rewrite(Error); TextRec(Error).Handle:= 2; or in the case of Delphi: program Meta2; .. Assign(Error, ''); Rewrite(Error); TTextRec(Error).Handle:= GetStdHandle(STD_ERROR_HANDLE); Is there a correct and portable way to do this using FPC?

I would think that

TTextRec(Error).Handle:=TTextRec(StdOut).Handle

Does the trick ?

Michael.

Reply by email

Mark Morgan Lloyd
to Michael Van Canneyt
Michael Van Canneyt wrote 5 lines
I would think that TTextRec(Error).Handle:=TTextRec(StdOut).Handle Does the trick ?

TextRec(StdErr) etc... it works and is certainly good enough. Program self-checks OK so I'm fairly confident it's ported correctly, now to start off with the object wrappers to see if it works in Lazarus as well as it does in Delphi.

Thanks for the help everybody, I'll go back to lurking quietly.

Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]

Reply by email