Proyecto

General

Perfil

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

{$mode objfpc}{$H+}

interface

uses
Classes, SysUtils,clservidor,process ;
var
miservidor:TServidor;
g_apagando:Boolean=false;
PUERTO_ROOT:integer=36999;
g_usuario:string=' ';
g_host:String='';
g_soy_canon:boolean=false;
g_activar_camara:Boolean=true;
f_contador_permisos:integer=5000;
f_contador:integer=140;
f_contador_usuario:integer=140;
f_servidor_creado:Boolean=false;
f_IpEquipo:String='';
g_tarjeta_red:String;
g_datosEnviados:Boolean=false;
g_cambioUsuario:Boolean=true;
g_usarioViejo:String='viejo';


procedure Ejecutar (comando:string);
function HallarDatos(Cmd:string):ansistring;

implementation
procedure Ejecutar (comando:string);
var
P: TProcess;
mproceso:string;
begin
P := TProcess.Create(nil);
try
mproceso:='sh -c '+QuotedStr(comando + ' 2>&1');
P.CommandLine := mproceso;
P.Execute;
finally
P.Free;
end;
end;
(*procedure Ejecutar (comando:string);
begin;
unix.fpSystem(comando);
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 .

(6-6/8)