NewProcess right after Process.Close?

delphi package - easy access to kernel objects etc.
Post Reply
Claes
Posts: 52
Joined: Thu Apr 22, 2004 10:52 pm
Location: Denmark

NewProcess right after Process.Close?

Post by Claes »

Hi Mathias!

I have the following code, where EXE is a valid filename for an executable on my system:

Code: Select all

var
  P: IProcess;
  Running, NeedRestart: Boolean;
begin
  P := Process(EXE);
  Running := P.IsStillRunning;
  NeedRestart := True; // just for testing

  if not Running or NeedRestart then
  begin
    if Running then P.Close;
    NewProcess(Path);
  end;
end;
If the app is NOT running, everything works as expected (i.e. the app is started). But if it is running, the app is closed, but not restarted. I suspect this is due to the process is not "entirely" closed when I executed NewProcess. How can I make this work using madKernel?

Regards, Claes
Claes
Posts: 52
Joined: Thu Apr 22, 2004 10:52 pm
Location: Denmark

Post by Claes »

Ok, it works with P.Terminate... But is there a cleaner solution?
madshi
Site Admin
Posts: 10754
Joined: Sun Mar 21, 2004 5:25 pm

Post by madshi »

You could use this

Code: Select all

P.Close;
P.WaitFor;
Does that help?
Claes
Posts: 52
Joined: Thu Apr 22, 2004 10:52 pm
Location: Denmark

Post by Claes »

Yes it did, thanks! ;-)
Post Reply