[Lazarus] send complex command to linux
Andrew Haines
AndrewD207 at aol.com
Wed Dec 22 17:40:08 CET 2010
On 12/22/10 04:58, Lukasz Sokol wrote:
> Very Nice, can I ask, just:
>
>
> [1]
>
>> while Flac.Running or (Flac.Output.NumBytesAvailable > 0) do
>> PipeOutput;
>>
>
> Can this conditon happen to hit
>
> Flac.Running=False
> ..NumBytesAvailable > 0 (it'll probably be some garbage, but still)
No. Flac.Output is not initialized until Flac.Execute has succeded.
As soon as Flac.Execute is called Flac.Running = true unless an error
occurred.
I did while loop like that in case Flac stopped running but we hadn't
finished reading all it's data.
>
> and would it be dangerous if so it happened ?
>
> Maybe another
> while not Flac.Running do
> begin
> Sleep(1);
> Application.ProcessMessages; // or even without this one
> end;
>
> be put at [1] ?
>
This *could* cause an inescapable loop if for instance flac exited
before this was reached because we gave it some wrong options.
A safer example would be:
begin
Flac := TProcess.Create(nil);
Flac.Commandline := 'flac <some options>';
Flac.Options = [poUsePipes];
try
Flac.Execute; // this will raise an exception if it
// cannot find or execute the command
except
ShowMessage('Error running Flac! Command Not Found');
end;
if not Flac.Running then
begin
// this will happen if flac ran but encountered
// problems
if Flax.ExitStatus <> 0 then
ShowMessage('Flac exited with an error: ' +
IntToStr(Flac.ExitStatus));
end
else // Flac ran and has already finished with some data or is still
running
begin
While Flac.Running or (Flac.Output.NumBytesAvailable > 0) do
PipeOutput;
end;
Flac.Free;
end;
Hope this clears things up :)
Regards,
Andrew
PS I didn't compile that so ther may be an error or three :)
More information about the Lazarus
mailing list