Starting a Detached Updater App lazarus / 32-Linux ---------------------------------------------------------------------- TheMouseAUS · 2024-09-17 03:33 Hi, I am trying to get an app I have made to self update. I have it checking a version number, then if an update is required, I want to run an updater app, close itself while the updater replaces the binary. I seem to be really struggling. Everything I try using the TProcess examples seems to close the updater app when the parent main app closes. Can some one please direct me to some TProcess examples that will actually work? Lazarus 3.4 FPC 3.2.2 x86_64_qt5 Thanks ---------------------------------------------------------------------- dsiders · 2024-09-17 03:43 Quote from: TheMouseAUS on September 17, 2024, 05:33:58 amHi, I am trying to get an app I have made to self update. I have it checking a version number, then if an update is required, I want to run an updater app, close itself while the updater replaces the binary. I seem to be really struggling. Everything I try using the TProcess examples seems to close the updater app when the parent main app closes. Can some one please direct me to some TProcess examples that will actually work? Lazarus 3.4 FPC 3.2.2 x86_64_qt5 Thanks Have a look at the startlazarus.lpr application in the ide directory. It handles the restart aspects. You have to include the update aspect. ---------------------------------------------------------------------- TheMouseAUS · 2024-09-17 05:13 what has startlazarus.lpr have to do with my app? I thought that was for the IDE itself? ---------------------------------------------------------------------- Thaddy · 2024-09-17 05:31 Yes, but it is a good example of what you want, especially TLazarusManager in LazarusManager.pas. On Windows you can start Tprocess with poDetached in the options, but I am not sure that works on Linux. This will keep the child process running even after the main app is closed. The lazarusmanager for linux uses waitforpid (the processid of the child proc) and then kills itself through fpKill. Just see how it is done in the LazarusManager class, which uses TProcessUTF8. So that was actually very good advice... ---------------------------------------------------------------------- TheMouseAUS · 2024-09-17 06:10 Oh I wasnt trying to say is was bad advice. I just didnt understand the advice I was being given. Thanks I will take a look. ---------------------------------------------------------------------- Thaddy · 2024-09-17 06:49 Don was a bit cryptic about the reasons. I hope my explanation helped to show that was really good advice and you should examine that code as an example on how to do that. Your first answer was a bit, let's say, premature? You would have seen it immediately if you followed his advice. ---------------------------------------------------------------------- TheMouseAUS · 2024-09-17 07:30 Oh I was definitely premature in my response. I should of looked more closely. I  am surprised how complicated it is. I just thought there was a simple way to open an external application and close the parent without issues but I was very wrong. It looks like startlazarus stays in memory and it executes the IDE. I am trying to figure out how it knows the IDE is requesting a restart as opposed to asking to close. ---------------------------------------------------------------------- TheMouseAUS · 2024-09-17 08:25 OK so I have implemented something similar. I have created a launcher that checks for a new copy of the app, if it exists it replaces the app then executes. When the app closes if a new copy exists it replaces and restarts otherwise closes. (I hope that makes sense) ---------------------------------------------------------------------- Thaddy · 2024-09-17 08:37 That is the correct order. Mind you, the old one needs to be renamed first. ---------------------------------------------------------------------- TheMouseAUS · 2024-09-17 08:48 Yes I forgot to mention that step it does rename the old one first