[Lazarus] send complex command to linux
Andrew Haines
AndrewD207 at aol.com
Sat Dec 18 21:04:39 CET 2010
On 12/18/10 13:49, ugaciaka wrote:
> Hi,
>
> this is an example of what I do
> ===================================================
>
> procedure TfrmMain.btnConvertClick(Sender: TObject);
> var
> enumFile : TStringsEnumerator;
> AProcess: TProcess;
> AStringList: TStringList;
> begin
> enumFile := clbFile.Items.GetEnumerator;
> AProcess := TProcess.Create(nil);
> AStringList := TStringList.Create;
>
> while enumFile.MoveNext do
> begin
> AProcess.CommandLine := 'flac -cd /home/ugaciaka/prova/prova.flac
> + | lame -h -b 320 - /home/ugaciaka/prova.mp3';
> AProcess.Options := AProcess.Options + [poWaitOnExit, poUsePipes];
> AProcess.Execute;
> AStringList.LoadFromStream(AProcess.Output);
> AStringList.SaveToFile('output.txt');
> end;
> AStringList.Free;
> AProcess.Free;
> end;
> ====================================================================
> but not function, *but* if I write
>
> AProcess.CommandLine := 'firefox gmail.google.com';
>
> my process running correctly firefox.
>
> In first case output.exe is similar to only ouput "lame".
>
> Any resolution?
Hi,
I solved your issue using two TProcess instances:
===================
function Min(A, B: Integer): Integer;
begin
if A > B then
Result := B
else
Result := A;
end;
procedure TForm1.ConvertFile(AFile: String);
var
Flac: TProcess;
Lame: TProcess;
NewFile: String;
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);
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;
while Flac.Running or (Flac.Output.NumBytesAvailable > 0) do
PipeOutput;
Flac.Free;
Lame.Free;
end;
=========================
Regards,
Andrew
More information about the Lazarus
mailing list