Cita:
Empezado por Ñuño Martínez
Free Pascal incluye la clase [url="http://www.freepascal.org/docs-html/fcl/process/tprocess.html"]TProcess[/URL
.....
Lo que no sé es si existe esta clase en Delphi, pero por lo que he leído por ahí no hay un equivalente claro.
|
Pues mira
http://www.elmalabarista.com/es/blog...ti-plataforma/
Asi es como la porte a Delphi
Y asi se usa:
Código Delphi
[-]
function TPlugin.RunDosInMemo(DosApp: String; StartDir:String): Boolean;
const
READ_BYTES = 2048;
var
AProcess: TProcess;
AStringList: TStringList;
n: Integer;
M: TMemoryStream;
BytesRead,BytesAvailable : LongInt;
begin
M:=TMemoryStream.Create;
AProcess := TProcess.Create(nil);
AStringList := TStringList.Create;
try
AProcess.CommandLine := DosApp;
AProcess.CurrentDirectory := StartDir;
AProcess.Options := AProcess.Options + [poUsePipes, poNoConsole];
BytesRead := 0;
AProcess.Execute;
LogMsg(IntToStr( AProcess.Handle ), msgStart );
while AProcess.Running do
begin
BytesAvailable := AProcess.Output.NumBytesAvailable;
n := AProcess.Output.Read(M.Memory^, BytesRead + BytesAvailable);
if n > 0
then begin
Inc(BytesRead, n);
end
else begin
end;
Sleep(250);
end;
repeat
BytesAvailable := AProcess.Output.NumBytesAvailable;
M.SetSize(BytesRead + BytesAvailable);
n := AProcess.Output.Read(M.Memory^, BytesRead + BytesAvailable);
if n > 0
then begin
Inc(BytesRead, n);
end;
until n <= 0;
M.SetSize(BytesRead);
LogMsg(IntToStr( AProcess.Handle ), msgEnd );
AStringList.LoadFromStream(M);
LastOutPut := AStringList.Text;
AStringList.Clear;
LastErrors := '';
AStringList.LoadFromStream(AProcess.Stderr);
if AStringList.Count>0 then
begin
LastErrors := StringReplace( AStringList.Text ,#13+#10,#13,[rfReplaceAll] );
end;
Result := (AProcess.ExitStatus = 0);
finally
AStringList.Free;
AProcess.Free;
end;end;
Desafortunadamente tiene un bug: Si el proceso DOS genera un output muy grande muy rapido se queda "colgado". No he podido ver todavia como arreglarlo...