[fpc-pascal] stdout refuses to be redirected

Frank Peelo f26p at eircom.net
Thu Oct 9 12:37:52 CEST 2008


Arjan van Dijk wrote:
>>You can stop using crt, then you don't need to change your write
>>instuctions.
> 
> 
> And how about my calls to READKEY and KEYPRESSED?
> Would unit WINCRT bring a solution?
> Or should I reconsider the use of these two statements anyhow?

One possibility is to assign the output file to ''.

For example, try the following:

uses crt;

Procedure DoIO(s:String);
var
   k : char;
Begin
   writeln(s);
   Writeln('Press keys. Hit Escape to stop.');
   repeat
     k := readkey;
     case k of
     ' '..#126: Write(k);
     #13:       writeln;
     else
       Begin
         sound(440);
         delay(200);
         nosound;
       end;
     end; { case k }
   until k=#27;
end;

Begin
   textcolor(yellow);
   DoIO('First call');

   assign(output, '');
   rewrite(output);
   DoIO('Second call');
end.


If you run this, the first call to DoIO uses the CRT unit. This comes 
out in colour, but cannot be redirected. The second call goes to stdout. 
This can be redirected but is not in colour.

(This is at least true in Windows XP and FPC 2.2.2)

Frank




More information about the fpc-pascal mailing list