Problems with SimpleIPC in communication between GUI and Console Programs lazarus / 62-General ---------------------------------------------------------------------- simone · 2019-01-07 10:51 I have some problems to implement Interprocess Comunication with SimpleIPC, in order to allow communication between a GUI program (the server, named ide in the attached files) and a console program (the client, named prog in the attached files). I would expect that when I start the server, after pressing the button, it runs the client that sends a message to show in the memo of server. But this does not happen. Moreover, if in server code I add Process.Options:=[poWaitOnExit], the client process freezes without doing anything. Can someone give me some hint? Many thanks. ---------------------------------------------------------------------- CCRDude · 2019-01-07 11:13 "unit1" is missing in the zip, and since prog.lpr doesn't show {$APPTYPE CONSOLE}, but instead embeds a form, I can only guess it's not really a console program, but a standard GUI program. ---------------------------------------------------------------------- simone · 2019-01-07 12:20 Unit1 is missing because does not exist such unit in the project. prog.lpr is an unused file. However I attach a new zip for your suggestions. ---------------------------------------------------------------------- simone · 2019-01-07 15:07 For convenience, I report the code on the web page. This is the server code: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program ide; {$mode objfpc}{$H+} uses  Interfaces, Forms, unit2; {$R *.res} begin  RequireDerivedFormResource:=True;  Application.Initialize;  Application.CreateForm(TForm1, Form1);  Application.Run;end. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i unit unit2; {$mode objfpc}{$H+} interface uses  Classes, SysUtils, SimpleIpc, FileUtil, Forms, Controls, Graphics, Dialogs,  StdCtrls, ExtCtrls, Process; type   { TForm1 }   TForm1 = class(TForm)    Button1: TButton;    Memo1: TMemo;    Panel1: TPanel;    SimpleIPCServer: TSimpleIPCServer;    SimpleIPCServer1: TSimpleIPCServer;    procedure Button1Click(Sender: TObject);    procedure SimpleIPCServer1MessageQueued(Sender: TObject);  private    Process : TProcess;  public   end; var  Form1: TForm1; implementation {$R *.lfm} { TForm1 } procedure TForm1.Button1Click(Sender: TObject);begin  SimpleIPCServer:=TSimpleIPCServer.Create(nil);  SimpleIPCServer.ServerID:='simone';  SimpleIPCServer.Global:=True;  SimpleIPCServer.OnMessageQueued:=@SimpleIPCServer1MessageQueued;  SimpleIPCServer.StartServer(False);   Process:=TProcess.Create(nil);  if FileExists('prog.exe') then    begin      Process.Executable:='prog.exe';      //Process.Options:=[poWaitOnExit];      Process.Execute;    end;  Process.Free;  SimpleIPCServer.Free;end; procedure TForm1.SimpleIPCServer1MessageQueued(Sender: TObject);var  Msg : string;begin  SimpleIPCServer.ReadMessage;  Msg:=SimpleIPCServer.StringMessage;  Memo1.Lines.Add(Msg);end; end. This is the client code: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program prog;{$mode objfpc}{$H+}uses  Classes,SimpleIpc,SysUtils;var  SimpleIPCClient: TSimpleIPCClient;begin  SimpleIPCClient:=TSimpleIPCClient.Create(nil);  SimpleIPCClient.ServerID:='simone';  if SimpleIPCClient.ServerRunning then    begin      SimpleIPCClient.Connect;      SimpleIPCClient.SendStringMessage('Hello!');    end;  SimpleIPCClient.Free;end. Thanks in advance for the help. ---------------------------------------------------------------------- ASerge · 2019-01-07 19:00 Quote from: simone on January 07, 2019, 04:07:55 pmThanks in advance for the help. Add after Process.Execute; SimpleIPCServer.PeekMessage(MSecsPerSec, False); or use SimpleIPCServer1 ---------------------------------------------------------------------- simone · 2019-01-10 10:33 Sorry for delay and thanks for the help. A further question: using TProcess, the process that launches the subprocess must run with administrator privileges? ---------------------------------------------------------------------- lucamar · 2019-01-10 13:48 Quote from: simone on January 10, 2019, 11:33:17 amSorry for delay and thanks for the help. A further question: using TProcess, the process that launches the subprocess must run with administrator privileges? No, it just needs to have enough privileges to run that particular executable. In Linux, for example, you can't normally run mount as a normal user ... but you can run sudo, which can do it by elevating the privileges.