Proyecto

General

Perfil

Descargar (2,57 KB) Estadísticas
| Rama: | Revisión:
unit global;

{$mode objfpc}{$H+}

interface
uses
Classes, SysUtils,process;
type
EDialogos = (Aceptar,SiNo);
TDialogo=Record
mensaje:string;
ClaseDialogo:Edialogos;
respuesta:integer;
end;
var
g_tiempoempleado:integer;
g_mihost, g_hostprofe,g_usuario,g_dirpersonal:string;
TipoDialogo:Tdialogo;
g_tarjeta_red:String;
function HallarDatos(Cmd:string):ansistring;
Function Mensaje(texto:string;clase:edialogos):integer;

implementation

uses dialogos;
Function Mensaje(texto:string;clase:edialogos):integer;
begin
tipodialogo.mensaje:=texto;;
tipodialogo.clasedialogo:=clase;
Tfrmdialogos.Create(nil).ShowModal;
result:=tipodialogo.respuesta;
frmdialogos.Free;
end;

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.


(8-8/11)