Club Delphi  
    Paypal   FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Otros temas > La Taberna
Registrarse FAQ Miembros Calendario Guía de estilo Buscar Temas de Hoy Marcar Foros Como Leídos

 
 
Herramientas Buscar en Tema Desplegado
  #5  
Antiguo 27-12-2024
Northern Northern is offline
Miembro
 
Registrado: ene 2006
Posts: 238
Poder: 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
 


Herramientas Buscar en Tema
Buscar en Tema:

Búsqueda Avanzada
Desplegado

Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro

Temas Similares
Tema Autor Foro Respuestas Último mensaje
en realidad los seres humanos..... sakuragi La Taberna 19 13-03-2008 09:22:17
Lápices hechos de humanos incinerados poliburro La Taberna 1 31-03-2007 07:37:35
¿Los informáticos somo Personas o Humanos? Delphius Debates 20 19-08-2004 03:01:17
Carta a Recursos Humanos Investment Humor 3 26-11-2003 23:53:17


La franja horaria es GMT +2. Ahora son las 09:09:15.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi
Copyright 1996-2007 Club Delphi