[fpc-pascal]popen problems...
Michael Van Canneyt
michael.vancanneyt at wisa.be
Wed Aug 14 16:34:40 CEST 2002
On Wed, 14 Aug 2002, Martyn Ranyard wrote:
>
> Hi all,
>
> I am writing a menu program in FPC, gpl'd so I'm asking here for
> comments, as I don't quite understand why my calls are no longer working.
>
> Procedure ExecAndDisplay(Command: String);
> Var
> TheFile : File;
> Ch : Char;
> TheBuff : String;
> EndOfFile : Boolean;
> Begin
> EndOfFile := False;
> popen(TheFile, Command, 'r');
> Repeat
> If not Eof(TheFile) then
You cannot do eof(thefile) on a binary file, because that one will
attempt to determine the position in the file. This is done using a
seek, and a seek on a pip is not legal.
The correct way to code this would be
Procedure ExecAndDisplay(Command: String);
Var
TheFile : File;
Ch : Char;
TheBuff : String;
EndOfFile : Boolean;
BytesRead : INteger;
Begin
Repeat
BlockRead(Thefile, Ch, 1,BytesRead)
If BytesRead<>1 then
begin
// ...
end
Until (bytesread=0);
Michael.
More information about the fpc-pascal
mailing list