robinhodemorais Posted February 28, 2020 Share Posted February 28, 2020 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 More sharing options...
azago Posted February 28, 2020 Share Posted February 28, 2020 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 More sharing options...
robinhodemorais Posted February 28, 2020 Author Share Posted February 28, 2020 I did the tests with this function but I couldn't make it work, it gives error Link to comment Share on other sites More sharing options...
robinhodemorais Posted February 28, 2020 Author Share Posted February 28, 2020 WinExec ('e:\Robinho\webSocket\startNodeJS.bat', SW_SHOW); in a test in vcl it executes, but that same command by unigui does not execute the command Link to comment Share on other sites More sharing options...
robinhodemorais Posted February 28, 2020 Author Share Posted February 28, 2020 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 More sharing options...
billyChou Posted February 29, 2020 Share Posted February 29, 2020 UNIGUI NEED IN EXE MODE, NOT ISAPI DLL , NOT SEVICE MODE, AND NEED PATH AND FILE Access rights. Link to comment Share on other sites More sharing options...
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now