[fpc-pascal] Ping problems - OS/X

Mattias Gaertner nc-gaertnma at netcologne.de
Wed May 21 11:25:35 CEST 2014


On Wed, 21 May 2014 11:11:11 +0200
Peter Brooks <peter.brooks at kchclinics.com> wrote:

> I've got a little program that just pings. It runs. I get a 0 error
> return, but there doesn't seem to be any output:
> 
> -rw-r--r--  1 root  wheel  0 21 May 11:09 output.txt
> 
> So it's re-writing the output.txt file, but the
> written(AstringList.Text) isn't putting anything there.
> 
> 
> This is almost a direct copy from the examples, so I'm not clear what
> I'm doing wrong. It could be that TStringList isn't working as I
> thought - because even the 'stdout:' doesn't appear in the file
> 'output.txt'. Or it could be that AProcess.Output isn't working.
> 
> Any suggestions?
> Free Pascal Compiler version 2.6.4 [2014/02/26] for i386
> OS/X 10.9.3
> 
> Program nmp(input,output);
> 
> uses
>   Classes, SysUtils,  Process;
> var
>   AProcess: TProcess;
>   AStringList: TStringList;
>   n :Integer;
> begin { main }
>   for n := 0 to 20 do
>         begin { for }
>         AStringList := TStringList.Create;
>         AProcess := TProcess.Create(nil);
>         AProcess.Executable := 'ping';
>         AProcess.Parameters.Add('-c 1');
>         AProcess.Parameters.Add('www.freepascal.org');
>         AProcess.Options := AProcess.Options + [poWaitOnExit, poUsePipes];
>         AProcess.Execute;
>         AStringList.SaveToFile('output.txt');
>         Writeln(n,' Execution Over: Exit Status: ',AProcess.ExitStatus);
>         AStringList.Add('stdout:');
>         AStringList.LoadFromStream(Aprocess.Output);
>         AStringList.Add('stderr:');
>         AStringList.LoadFromStream(AProcess.Stderr);
>         AStringList.LoadFromStream(AProcess.Output);
>         writeln(AStringList.Text);

Move it here:
AStringList.SaveToFile('output.txt');

>         AstringList.Free;
>         AProcess.Free;
>         end; {for}
> close(output) {added just in case it was losing the write}
> end.

Mattias



More information about the fpc-pascal mailing list