Recent

Author Topic: TProcess cant Execute Programm  (Read 1203 times)

Weitentaaal

  • Hero Member
  • *****
  • Posts: 554
TProcess cant Execute Programm
« on: June 30, 2021, 01:23:27 pm »
Hello Guys,

was wondering if Someone could answer this Thread : https://forum.lazarus.freepascal.org/index.php/topic,8578.msg41444.html#msg41444

I get the same Error Message please Help.

Process is not Running

Code below:
Code: Pascal  [Select][+][-]
  1.                Bb := TProcess.Create(Nil);
  2.  
  3.                //Some not that important Code
  4.  
  5.                try
  6.                   Bb.Executable:=('C:\WGKBlck\KVS\KVDesigner.exe');
  7.                   //Bb.Parameters.Add('C:\WGKBlck\Data\WGK2KVS.KVS') //not need just a normal exe without any Params
  8.  
  9.                   Bb.Execute;
  10.                finally
  11.                   Bb.Free;
  12.                end;
  13.  

vangli

  • Jr. Member
  • **
  • Posts: 56
Re: TProcess cant Execute Programm
« Reply #1 on: June 30, 2021, 01:45:57 pm »
Have you defined "Bb" as a variable?

Code: Pascal  [Select][+][-]
  1. var
  2.   Bb : TProcess;

Regards Bent

Zvoni

  • Hero Member
  • *****
  • Posts: 3361
Re: TProcess cant Execute Programm
« Reply #2 on: June 30, 2021, 01:54:31 pm »
I'm missing poWaitOnExit for the Options
As of now (the code we see), you execute, and free it immediatley afterwards.
Maybe it does execute, you just don't see it
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

Bart

  • Hero Member
  • *****
  • Posts: 5713
    • Bart en Mariska's Webstek
Re: TProcess cant Execute Programm
« Reply #3 on: June 30, 2021, 02:08:39 pm »
poWaitOnExit is an option, not a must.
The process is only freead after Execute returns.
At that point the executable is already running (or it failed to do so).

Try to do some simple debugging
Code: Pascal  [Select][+][-]
  1. var
  2.   Bp: TProcess;
  3.   Err: Integer;
  4. begin
  5.   Bp := TProcess.Create(nil);
  6.   Bp.Options := [poWaitOnExit]; //not really needed
  7.   Bp.Executable := 'C:\WGKBlck\KVS\KVDesigner.exe';
  8.   try
  9.     Bp.Execute;
  10.   except
  11.     on E: EProcess do
  12.     begin
  13.       Err := GetLastOSError;
  14.       writeln(Format('GetLastOSError = %d: "%s"',[Err,SysErrorMessage(Err)]));
  15.     end;
  16.   end;
  17.   writeln('ExitCode: ',Bp.ExitCode);
  18.   writeln('ExitStatus: ',Bp.ExitStatus);
  19.   Bp.Free;
  20. end;

Since I don;t have this file it says:
Code: [Select]
GetLastOSError = 2: "Het systeem kan het opgegeven bestand niet vinden." //The system cannot find the given path
ExitCode: 0
ExitStatus: 0

Bart

 

TinyPortal © 2005-2018