Recent

Author Topic: Starting another application while terminating the actual one  (Read 7006 times)

99Percent

  • Full Member
  • ***
  • Posts: 160
Starting another application while terminating the actual one
« on: October 11, 2010, 05:23:11 am »
How do you begin execution on another application while simultaneously terminating the actual program? I need to do this so that the other application can delete the executable file.

Sorry if this is explained in the wiki, but the wiki is down (yet again).

Zoran

  • Hero Member
  • *****
  • Posts: 1831
    • http://wiki.lazarus.freepascal.org/User:Zoran
Re: Starting another application while terminating the actual one
« Reply #1 on: October 11, 2010, 07:48:49 am »
I don't think that it can be done. However, what you intend may be done by using another program which starts the first application, then after closing it, deletes it.

As I understand, that is what the startlazarus program does with lazarus (after you rebuild the IDE, it terminates lazarus process, deletes lazarus exe file and replaces it with the newly created one, then starts it).

Leledumbo

  • Hero Member
  • *****
  • Posts: 8757
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Starting another application while terminating the actual one
« Reply #2 on: October 11, 2010, 08:11:46 am »
You can, try this:
Code: [Select]
with TProcess.Create(nil) do
  try
    CommandLine := 'Replace with your program';
    Options := [];
    Execute;
  finally
    Free;
  end;

ivan17

  • Full Member
  • ***
  • Posts: 173
Re: Starting another application while terminating the actual one
« Reply #3 on: October 11, 2010, 10:25:54 pm »
to quote the wiki
Quote from: WIKI
The simplest way if you don't need pipes or any form of control is to simply use SysUtils.ExecuteProcess('/full/path/to/binary',['arg1','arg2']);
so just do that and terminate your application.

meanwhile second application (without forms but non-console) should do this:
Code: [Select]
begin
  while DeleteFile('app1') = false do Sleep(500);  // if can't delete (locked), wait half a sec and try again
end.


see that there is only one instance of main program active.

Leledumbo

  • Hero Member
  • *****
  • Posts: 8757
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Starting another application while terminating the actual one
« Reply #4 on: October 13, 2010, 06:25:37 am »
Quote
so just do that and terminate your application.
You can't, AFAIK SysUtils.ExecuteProcess blocks program execution.

ivan17

  • Full Member
  • ***
  • Posts: 173
Re: Starting another application while terminating the actual one
« Reply #5 on: October 13, 2010, 05:26:29 pm »
You can't, AFAIK SysUtils.ExecuteProcess blocks program execution.
my bad, never really used that one; ok then TProcess without poWaitOnExit in options.

 

TinyPortal © 2005-2018