Ver Mensaje Individual
  #2  
Antiguo 18-06-2024
Avatar de duilioisola
[duilioisola] duilioisola is offline
Miembro Premium
 
Registrado: ago 2007
Ubicación: Barcelona, España
Posts: 1.806
Reputación: 22
duilioisola Es un diamante en brutoduilioisola Es un diamante en brutoduilioisola Es un diamante en bruto
RunAndWait para Windows.
Si avriguas como hacerlo en Linux puedes tener la misma función compilada según un {$IFDEF WIN32} ...{$ENDIF WIN32}, {$IFDEF LINUX}...{$ENDIF LINUX}.

Código Delphi [-]
function RunAndWait(Handle: THandle; Ejecutable, Argumentos: string; const RunDirectory: PChar = nil; const Visibilidad: integer = SW_SHOWNORMAL; MensajeSiCorrecto: boolean = True): DWORD;
var
  Info : TShellExecuteInfo;
  pInfo : PShellExecuteInfo;
  ExitCode : word;
  P : PChar;
begin
  { Puntero a Info }
  { Pointer to Info }
  pInfo := @Info;
  { Rellenamos Info }
  { Fill info }
  with Info do
  begin
     cbSize := SizeOf(Info);
     fMask := SEE_MASK_NOCLOSEPROCESS;
     wnd := Handle;
     lpVerb := nil;
     lpFile := PChar(Ejecutable);
     { Parametros al ejecutable }
     { Executable parameters }
     lpParameters := PChar(Argumentos + #0);
     if RunDirectory = '' then
        lpDirectory := nil
     else
        lpDirectory := PChar(RunDirectory + #0);
     nShow := Visibilidad;
     hInstApp := 0;
  end;
  { Ejecutamos }
  { Execute }
  if not ShellExecuteEx(pInfo) then
  begin
     Result := GetLastError;
     if FormatMessage(Format_Message_Allocate_Buffer + Format_Message_From_System,
        nil,
        Result,
        0, @P,
        0,
        nil) <> 0 then
     begin
        // Display the string.
        ShowMessage(P);
        // Free the buffer.
        LocalFree(integer(P));
     end;
  end
  else
     Result := 0; // Info.hInstApp;

  { Esperamos que termine }
  { Wait to finish }
  repeat
     ExitCode := WaitForSingleObject(Info.hProcess, 500);
     Application.ProcessMessages;
  until (ExitCode <> WAIT_TIMEOUT);
  ExitCode := GetLastError;

  GetExitCodeProcess(Info.hProcess, Result);
  if ((Result < 32) and (ExitCode = 0)) then
  begin
     ExitCode := GetLastError;
     if FormatMessage(Format_Message_Allocate_Buffer + Format_Message_From_System,
        nil,
        ExitCode,
        0, @P,
        0,
        nil) <> 0 then
     begin
        // Display the string.
        if MensajeSiCorrecto or (ExitCode <> 0) then
           ShowMessage(P);
        // Free the buffer.
        LocalFree(integer(P));
     end;
  end
  else
     Result := 0; // Info.hInstApp;
end;
Responder Con Cita