Recent

Author Topic: TProcess bug on cocoa?  (Read 688 times)

xinyiman

  • Hero Member
  • *****
  • Posts: 1960
    • Lazarus and Free Pascal italian community
TProcess bug on cocoa?
« on: May 13, 2019, 03:30:19 pm »
Hi guys, from my application I have to launch a second application and wait for it to finish. Looking at the TProcess parameters I see written:

poWaitOnExit    Wait for the process to terminate before returning.

But this is not the case, the program is launched but my program is not blocked. Does anyone know why?

Code: Pascal  [Select]
  1. var
  2.   AProcess     : TProcess;
  3. begin
  4.   AProcess := TProcess.Create(nil);
  5.  
  6.   AProcess.Executable := name_exe;
  7.  
  8.   AProcess.Options := [poWaitOnExit, poNewConsole];
  9.  
  10.   AProcess.Execute;
  11.  
  12.   AProcess.Free;  
  13.  
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2280
    • havefunsoft.com
Re: TProcess bug on cocoa?
« Reply #1 on: May 13, 2019, 04:23:05 pm »
But this is not the case, the program is launched but my program is not blocked. Does anyone know why?
two reasons:
- the app launched but exited immediately
- the app didn't launch at all (and an error was returned)
Patron Cocoa Widgetset development https://www.patreon.com/skalogryz

xinyiman

  • Hero Member
  • *****
  • Posts: 1960
    • Lazarus and Free Pascal italian community
Re: TProcess bug on cocoa?
« Reply #2 on: May 13, 2019, 04:42:12 pm »
No, because I saw that the program started correctly but went immediately beyond.
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2280
    • havefunsoft.com
Re: TProcess bug on cocoa?
« Reply #3 on: May 13, 2019, 04:47:01 pm »
No, because I saw that the program started correctly but went immediately beyond.
what does "went beyond" mean? maybe it did shut down.
Patron Cocoa Widgetset development https://www.patreon.com/skalogryz

xinyiman

  • Hero Member
  • *****
  • Posts: 1960
    • Lazarus and Free Pascal italian community
Re: TProcess bug on cocoa?
« Reply #4 on: May 14, 2019, 08:10:15 am »
I mean that my program is not blocked when the external program is launched. It means that after doing the execute it goes immediately to free without waiting for the program I launched to close

   AProcess.Execute;
 
   AProcess.Free;
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

ccrause

  • Full Member
  • ***
  • Posts: 185
Re: TProcess bug on cocoa?
« Reply #5 on: May 14, 2019, 11:37:35 am »
<update> Sorry, didn't notice this was a MacOS/cocoa specific problem. Code example below should be adapted to call an application available in cocoa...</update>

To test if the launched process is still running after AProcess.Execute:
Code: Pascal  [Select]
  1. program project1;
  2.  
  3. uses process;
  4.  
  5. var AProcess: TProcess;
  6.  
  7. begin
  8.   AProcess := TProcess.Create(nil);
  9.   AProcess.Executable := 'C:\Windows\System32\cmd.exe';
  10.   AProcess.Parameters.Text := '/k';
  11.   AProcess.Options := [poWaitOnExit, poNewConsole];
  12.   AProcess.Execute;
  13.  
  14.   if AProcess.Running then
  15.     writeln('Error - launched process still running.')
  16.   else
  17.     writeln('OK - launched process not running.');
  18.  
  19.   AProcess.Free;
  20. end.    

This example waits correctly (in Windows) until one closes the console opened by cmd.exe.  Tested with FPC 3.0.4 (64 bit) on Windows 10. skalogryz gave two very valid scenarios that could explain your observation.  Could you give more detail of your setup (OS, external application name, fpc version)?  Also, can you see that the original launched process is still running (by checking the launched process command line in e.g. task manager, ps, top etc.Activity Monitor) after AProcess.Execute returns?
« Last Edit: May 14, 2019, 11:48:31 am by ccrause »

xinyiman

  • Hero Member
  • *****
  • Posts: 1960
    • Lazarus and Free Pascal italian community
Re: TProcess bug on cocoa?
« Reply #6 on: May 14, 2019, 11:48:06 am »
My mac: mac os sierra 10.12.6
Lazarus version: Lazarus 2.1.0 r60408M FPC 3.3.1 x86_64-darwin-cocoa (alpha)
Code: Pascal  [Select]
  1.  
  2. program project1;
  3.  
  4. uses process;
  5.  
  6. var AProcess: TProcess;
  7.  
  8. begin
  9.   AProcess := TProcess.Create(nil);
  10.   AProcess.Executable := '/tmp/myapp.app';
  11.   AProcess.Options := [poWaitOnExit, poNewConsole];
  12.   AProcess.Execute;
  13.  
  14.   AProcess.Free;
  15. end.  
  16.  
  17.  
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

josh

  • Hero Member
  • *****
  • Posts: 754
Re: TProcess bug on cocoa?
« Reply #7 on: May 14, 2019, 01:03:17 pm »
Hi

Not at my mac at the moment, but could this be down to executing a .app, as this is the Bundle, that can contain multiple binaries that can launch from the click of the bundle.
Maybe the .app part has indeed completed it tasks as soon as the assocaited binary(s) are running.

WOuld need to test on my mac though, but cant do until much later today..
Development Installation Lazarus 1.3, FPC 2.7.1,Windows 7/8 32/64, OSX, *nix

Test Environment Lazarus & FPC Trunk on Windows and OSX (Cocoa Mainly on OSX). Testing also Crosscompile windows to OSX.. 
Any posts made from 2015 will be based on Lazarus Trunk.

xinyiman

  • Hero Member
  • *****
  • Posts: 1960
    • Lazarus and Free Pascal italian community
Re: TProcess bug on cocoa?
« Reply #8 on: May 14, 2019, 01:41:58 pm »
I'm in no hurry. The problem is that if I don't go through the app, it opens the console to launch the executable and I don't want to.
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2280
    • havefunsoft.com
Re: TProcess bug on cocoa?
« Reply #9 on: May 14, 2019, 04:12:56 pm »
I'm in no hurry. The problem is that if I don't go through the app, it opens the console to launch the executable and I don't want to.
try to change:
AProcess.Options := [poWaitOnExit, poNewConsole];
to
AProcess.Options := [poWaitOnExit, poNoConsole];
or
AProcess.Options := [poWaitOnExit];
Patron Cocoa Widgetset development https://www.patreon.com/skalogryz

xinyiman

  • Hero Member
  • *****
  • Posts: 1960
    • Lazarus and Free Pascal italian community
Re: TProcess bug on cocoa?
« Reply #10 on: May 14, 2019, 04:51:04 pm »
Actually the problem seems to be the bundle. If I start the executable without going through the * .app file it seems to work. Tomorrow I will do extensive tests. For the moment, thanks
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1