desarrollosconsejeria/aulalinex-portatil-alumno/4.2-16/aulalinexcuestion/global.pas @ master
a2ba555f | Elisa | unit global;
|
|
{$mode objfpc}{$H+}
|
|||
interface
|
|||
uses
|
|||
Classes, SysUtils,process;
|
|||
var
|
|||
g_tiempoempleado:integer;
|
|||
g_usuario,g_dirpersonal:string;
|
|||
g_codigo,g_tipoc:string;
|
|||
g_num_opciones,g_tiempoc:integer;
|
|||
g_pregunta:string;
|
|||
g_opciones:array of string;
|
|||
g_tiempo:integer;
|
|||
g_hostprofe:string='192.168.0.254';
|
|||
g_mihost:string;
|
|||
g_tarjeta_red:String;
|
|||
function HallarDatos(Cmd:string):ansistring;
|
|||
implementation
|
|||
function HallarDatos(Cmd:string):ansistring;
|
|||
const
|
|||
READ_BYTES = 2048;
|
|||
var
|
|||
S: TStringList;
|
|||
M: TMemoryStream;
|
|||
P: TProcess;
|
|||
n: LongInt;
|
|||
BytesRead: LongInt;
|
|||
ssalida:ansistring;
|
|||
mproceso:string;
|
|||
begin
|
|||
mproceso:='sh -c '+QuotedStr(Cmd + ' 2>&1');
|
|||
S := TStringList.Create;
|
|||
M := TMemoryStream.Create;
|
|||
BytesRead := 0;
|
|||
P := TProcess.Create(nil);
|
|||
try
|
|||
try
|
|||
P.CommandLine := mproceso;
|
|||
P.Options := [poUsePipes];
|
|||
P.Execute;
|
|||
while P.Running do
|
|||
begin
|
|||
M.SetSize(BytesRead + READ_BYTES);
|
|||
n := P.Output.Read((M.Memory + BytesRead)^, READ_BYTES);
|
|||
if n > 0 then
|
|||
begin
|
|||
Inc(BytesRead, n);
|
|||
end
|
|||
else
|
|||
begin
|
|||
Sleep(100);
|
|||
end;
|
|||
end;
|
|||
repeat
|
|||
M.SetSize(BytesRead + READ_BYTES);
|
|||
n := P.Output.Read((M.Memory + BytesRead)^, READ_BYTES);
|
|||
if n > 0 then
|
|||
begin
|
|||
Inc(BytesRead, n);
|
|||
Write('.');
|
|||
end;
|
|||
until n <= 0;
|
|||
M.SetSize(BytesRead);
|
|||
S.LoadFromStream(M);
|
|||
ssalida:=trim(S.text);
|
|||
except
|
|||
ssalida:='Error al ejecutar proceso. Comando o parámetros no validos';
|
|||
end;
|
|||
finally
|
|||
S.Free;
|
|||
P.Free;
|
|||
M.Free;
|
|||
result:=ssalida;
|
|||
end;
|
|||
end;
|
|||
end.
|
|||