[fpc-pascal] stdout refuses to be redirected

Vincent Snijders vsnijders at vodafonevast.nl
Thu Oct 9 10:30:19 CEST 2008


Arjan van Dijk schreef:
> Hi!
> 
> The following small piece of code, with filename 'test.pas':
> 
> PROGRAM Test;
> USES CRT,DOS;
> VAR
>   DirInfo: SEARCHREC;
> BEGIN
>   FINDFIRST('*.pas',ARCHIVE,DirInfo);
>   WRITELN(DirInfo.Name);
> END.
> 
> just gives the name of the first file with extension ".pas".
> It compiles and runs fine when I call is as follows:
> 
> test.exe
> 
> Now when I try to redirect the output to a file, then that file remains
> empty:
> 
> test.exe > somefile
> 
> This is the narrowed down version of my malfunctioning program.
> Can someone please have a look into this? A whole lot of interesting
> calculations (and my boss...) are waiting for this problem to be fixed.

I have two suggestions, untested.

1. Don't use the crt unit, it grabs the handling of output (writeln(s) 
is translated to writeln(output,s);

2. Use writeln(stdout, DirInfo.Name) to bypass crt's handling of output.

Vincent



More information about the fpc-pascal mailing list