Forcing a text file to use a predefined handle

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Forcing a text file to use a predefined handle

Mark Morgan Lloyd-5
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]
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Forcing a text file to use a predefined handle

Michael Van Canneyt


On Sat, 20 Dec 2008, Mark Morgan Lloyd wrote:

> 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.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Forcing a text file to use a predefined handle

Mark Morgan Lloyd-5
Michael Van Canneyt wrote:

> 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]
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal