[Lazarus] send complex command to linux
Lukasz Sokol
el.es.cr at gmail.com
Wed Dec 22 10:58:44 CET 2010
Very Nice, can I ask, just:
On 21/12/2010 20:29, Andrew Haines wrote:
[...]
> ====== code ========
> procedure TForm1.ConvertFile(AFile: String);
> var
> Flac: TProcess;
> Lame: TProcess;
> NewFile: String;
> Line: String;
> procedure FillStdErr;
> var
> Buf: Char;
> FPos, i: Integer;
> begin
> while Flac.Stderr.NumBytesAvailable > 0 do
> begin
> Flac.Stderr.Read(Buf,1);
> if Buf in [#13, #10] then
> begin
> if Length(Line) > 0 then
> ListBox1.Items.Add(Line);
> FPos := Pos('%', Line);
> if FPos > 0 then
> begin
> i := FPos;
> while Line[i] <> ' ' do
> dec (i);
> Line := Copy(Line, i, FPos-i);
> ProgressBar1.Position:=StrToInt(Line); // 0 to 100
> representing percent
> end;
> Line := '';
> Application.ProcessMessages; // so progress bar is updated
> end
> else
> Line := Line + Buf;
> end;
> end;
> procedure PipeOutput;
> var
> Buffer: array[0..127] of byte;
> RCount: Integer;
> begin
> if Flac.Output.NumBytesAvailable > 0 then
> begin
> RCount := Flac.Output.Read(Buffer, Min(128,
> Flac.Output.NumBytesAvailable));
> Lame.Input.Write(Buffer, RCount);
> end
> else
> Sleep(1);
> FillStdErr;
> end;
>
>
> begin
> NewFile := ExtractFileNameWithoutExt(AFile)+'.mp3';
> Flac := TProcess.Create(nil);
> Lame := TProcess.Create(nil);
> Flac.CommandLine := 'flac -cd '+ AFile;
> Lame.CommandLine := 'lame -h -b 320 - '+ NewFile;
>
> Flac.Options := [poUsePipes];
> Lame.Options := [poUsePipes];
>
> Flac.Execute;
> Lame.Execute;
>
[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)
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] ?
Lukasz
>
> ListBox1.Items.Add(Line);
>
> Flac.Free;
> Lame.Free;
> end;
More information about the Lazarus
mailing list