Ver Mensaje Individual
  #5  
Antiguo 27-12-2024
Northern Northern is offline
Miembro
 
Registrado: ene 2006
Posts: 238
Reputación: 21
Northern Va por buen camino
Cita:
Empezado por mamcx Ver Mensaje
Bueno, esas IA hicieron eso: Fueron alimentadas con la información que tomaron de todos nosotros (entre ellas las de foros, programadores, repositorios open source, etc) donde estaba la respuesta.

Es muy impresionante. Pero es muy riesgosa porque la IA no sabe si lo que encontró es o no es cierto, y si tampoco lo sabe el humano...

Ciertamente nadie nace aprendido y las IAs tampoco pero decirle a una IA: oye IA, una función en Delphi que escriba "cmd netstat" envíe la salida a un TMemo



Hasta ahí y que en menos de 5 segundos te dé la respuesta no me digas que no es una pasada y esta fue su respuesta


Código Delphi [-]
function EjecutarCmdYCapturarSalida(const Command: string; Memo: TMemo): Boolean;
var
  SecurityAttr: TSecurityAttributes;
  ReadPipe, WritePipe: THandle;
  StartInfo: TStartupInfo;
  ProcInfo: TProcessInformation;
  Buffer: array[0..4096] of AnsiChar;
  BytesRead: DWORD;
  CommandLine: string;
  Output: TStringList;
begin
  Result := False;
  Memo.Lines.Clear;
  Output := TStringList.Create;

  try
    // Configurar seguridad del pipe
    ZeroMemory(@SecurityAttr, SizeOf(SecurityAttr));
    SecurityAttr.nLength := SizeOf(SecurityAttr);
    SecurityAttr.bInheritHandle := True;

    // Crear pipe para redirigir la salida estándar
    if not CreatePipe(ReadPipe, WritePipe, @SecurityAttr, 0) then
      Exit;

    try
      // Asegurarse de que el extremo de escritura no sea heredado por el proceso hijo
      if not SetHandleInformation(ReadPipe, HANDLE_FLAG_INHERIT, 0) then
        Exit;

      // Configurar StartupInfo para redirigir salida
      ZeroMemory(@StartInfo, SizeOf(StartInfo));
      StartInfo.cb := SizeOf(StartInfo);
      StartInfo.hStdOutput := WritePipe;
      StartInfo.hStdError := WritePipe;
      StartInfo.dwFlags := STARTF_USESTDHANDLES;

      ZeroMemory(@ProcInfo, SizeOf(ProcInfo));

      // Construir el comando completo
      CommandLine := Format('cmd /C %s', [Command]);

      // Crear el proceso
      if CreateProcess(nil, PChar(CommandLine), nil, nil, True, CREATE_NO_WINDOW, nil, nil, StartInfo, ProcInfo) then
      begin
        CloseHandle(WritePipe); // El proceso principal no escribe en el pipe

        // Leer la salida del pipe
        while ReadFile(ReadPipe, Buffer, SizeOf(Buffer) - 1, BytesRead, nil) and (BytesRead > 0) do
        begin
          Buffer[BytesRead] := #0; // Terminar el buffer
          Output.Text := Output.Text + String(Buffer);
        end;

        // Esperar a que el proceso termine
        WaitForSingleObject(ProcInfo.hProcess, INFINITE);

        // Mostrar la salida en el TMemo
        Memo.Lines.Text := Output.Text;

        Result := True;
      end;

    finally
      // Cerrar handles
      CloseHandle(ReadPipe);
      CloseHandle(WritePipe);
      CloseHandle(ProcInfo.hProcess);
      CloseHandle(ProcInfo.hThread);
    end;
  finally
    Output.Free;
  end;
end;


Esto en 2020 era impensable y a saber qué viene el año que viene


Responder Con Cita