Jump to content

run bat


robinhodemorais

Recommended Posts

Looking for how to run a stick with a single topic from that topic http://forums.unigui.com/index.php?/topic/3356-how-to-call-a-executable-file-on-server-side-within- unigui / where mhmda passes a procedure to execute, but I'm trying to implement it in my application and I'm not getting it ...
when I'm in the development environment running autonomously, I need to execute a stick that is at the root of the root, this type of stop starts the service node of the service, or what I notice is that it appears quickly or that closes but I I can see something.

in the bat file is in the following configuration

Quote

cd E: \ Delphi Projects \ socket
server.js node

bat name startNodeJS.bat

Link to comment
Share on other sites

Starting an exe is a purely delphi language solution (no UniGUI).
It all depends on whether you need a return output from running the process.
In the latter case you have to use a semaphores management (also via file).

However I have used it in UNIGUI in this way:

// call
var
   NameExec     : string;
   NameFileJSON : string;
   rc       : word;
begin
    // exec process
    if dmDataset.ExecFile(NameExec, NameFileJSON, rc) then begin
       // timer OnThreadTerminate type TUniTimer for file response
       OnThreadTerminate.Enabled := True;
    end;        
end;

// function in Datamodule
function TdmDataset.ExecFile(const sComand, sParameter : string; var rc : word) : boolean;
var
   SI                        : TStartupInfo;
   PI                        : TProcessInformation;
   sCmd                    : string;
begin
   Result             := True;

   FillChar(SI, SizeOf(SI), 0);
   SI.cb := SizeOf(SI);
   SI.wShowWindow := SW_SHOWMINNOACTIVE;

   sCmd := sComand;
   if sParameter > '') then sCmd := sCmd + ' ' + sParameter;

   if (Not CreateProcess(Nil, PChar(sCmd), Nil, Nil, False,
             Normal_Priority_Class, Nil, Nil, SI, PI)) then begin
      rc     := GetLastError;
      Result     := (rc = 0);
      exit;
   end;

   CloseHandle(PI.hThread);
end;

procedure OnThreadTerminateTimer(Sender: TObject);
var
   FFolder     : string;
   Sr          : TSearchRec;
   FileDownload: string;
   SearchStr   : string;
begin
   // Response dir     
   FFolder := IncludeTrailingPathDelimiter(UniMainModule.Configurazione.PathLocal);

   SearchStr    := '*.json';

   if SysUtils.FindFirst(FFolder + SearchStr, faAnyFile, Sr) = 0 then
   begin
      repeat
         if Sr.Attr and faDirectory = 0 then begin
            if UpperCase(ExtractFileName(ChangeFileExt(Sr.Name, ''))) = 'RESPONSE' then begin
               // fistr disable
               OnThreadTerminate.Enabled := False;

               // action business -- download -- other ---
               UniSession.SendFile(IncludeTrailingPathDelimiter(UniMainModule.Configurazione.PathLocal) + ExtractFileName(Sr.Name), FileDownload);

               // send message
               dmToast.Success('Download. Scarico eseguito.');

               Break;
            end;
         end;
      until SysUtils.FindNext(sr) <> 0;
      SysUtils.FindClose(sr);
   end;
 

Link to comment
Share on other sites

14 hours ago, azago said:

Starting an exe is a purely delphi language solution (no UniGUI).
It all depends on whether you need a return output from running the process.
In the latter case you have to use a semaphores management (also via file).

However I have used it in UNIGUI in this way:

// call
var
   NameExec     : string;
   NameFileJSON : string;
   rc       : word;
begin
    // exec process
    if dmDataset.ExecFile(NameExec, NameFileJSON, rc) then begin
       // timer OnThreadTerminate type TUniTimer for file response
       OnThreadTerminate.Enabled := True;
    end;        
end;

// function in Datamodule
function TdmDataset.ExecFile(const sComand, sParameter : string; var rc : word) : boolean;
var
   SI                        : TStartupInfo;
   PI                        : TProcessInformation;
   sCmd                    : string;
begin
   Result             := True;

   FillChar(SI, SizeOf(SI), 0);
   SI.cb := SizeOf(SI);
   SI.wShowWindow := SW_SHOWMINNOACTIVE;

   sCmd := sComand;
   if sParameter > '') then sCmd := sCmd + ' ' + sParameter;

   if (Not CreateProcess(Nil, PChar(sCmd), Nil, Nil, False,
             Normal_Priority_Class, Nil, Nil, SI, PI)) then begin
      rc     := GetLastError;
      Result     := (rc = 0);
      exit;
   end;

   CloseHandle(PI.hThread);
end;

procedure OnThreadTerminateTimer(Sender: TObject);
var
   FFolder     : string;
   Sr          : TSearchRec;
   FileDownload: string;
   SearchStr   : string;
begin
   // Response dir     
   FFolder := IncludeTrailingPathDelimiter(UniMainModule.Configurazione.PathLocal);

   SearchStr    := '*.json';

   if SysUtils.FindFirst(FFolder + SearchStr, faAnyFile, Sr) = 0 then
   begin
      repeat
         if Sr.Attr and faDirectory = 0 then begin
            if UpperCase(ExtractFileName(ChangeFileExt(Sr.Name, ''))) = 'RESPONSE' then begin
               // fistr disable
               OnThreadTerminate.Enabled := False;

               // action business -- download -- other ---
               UniSession.SendFile(IncludeTrailingPathDelimiter(UniMainModule.Configurazione.PathLocal) + ExtractFileName(Sr.Name), FileDownload);

               // send message
               dmToast.Success('Download. Scarico eseguito.');

               Break;
            end;
         end;
      until SysUtils.FindNext(sr) <> 0;
      SysUtils.FindClose(sr);
   end;
 

how do i call a stick or pass a command with that function you did?

Link to comment
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...