Jump to content

how to Execute application on server side and wait for completion


Recommended Posts

eu usso isso:

 

{CHAMA EXECUTAVEL PASSANDO PARAMETROS, ESPERA FINALIZACAO DO MESMO}
function ExecutaeAguarda(const FileName, Params:String; const WindowState: Word): boolean;
var
  SUInfo: TStartupInfo;
  ProcInfo: TProcessInformation;
  CmdLine:String;
begin
result :=false;
if (NOT FILEEXISTS(FileName)) and (pos('\',FileName)>0) then
   BEGIN
     alerta('Arquivo '+FileName+#13+'não foi encontrado!');
     exit;
   END;
 
  CmdLine := '"' + Filename + '"' + Params;
  FillChar(SUInfo, SizeOf(SUInfo), #0);
 
  With SUInfo do
   begin
    cb := SizeOf(SUInfo);
    dwFlags := STARTF_USESHOWWINDOW;
    wShowWindow := WindowState;
   end;
  Result := CreateProcess(nil,
                          PChar(CmdLine),
                          nil,
                          nil,
                          false,
                          CREATE_NEW_CONSOLE or NORMAL_PRIORITY_CLASS,
                          nil,
                          PChar(ExtractFilePath(Filename)),
                          SUInfo,
                          ProcInfo);
  if Result then
    begin
     WaitForSingleObject(ProcInfo.hProcess, INFINITE);
     CloseHandle(ProcInfo.hProcess);
     CloseHandle(ProcInfo.hThread);
    end;
end;
 
 
params :='"PARAM" "PARAM2" "PARAM3"';
ExecutaeAguarda(UniServerModule.ServerRoot+'\yourexe.exe',params,SW_NORMAL)   //SW_MINIMIZE SW_HIDE ....
 
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...