Recent

Author Topic: Issue with poNewConsole and poWaitOnExit on Linux  (Read 2334 times)

Giorgio Tani

  • New Member
  • *
  • Posts: 21
Issue with poNewConsole and poWaitOnExit on Linux
« on: March 07, 2021, 10:30:59 pm »
Hello, in the documentation poNewConsole TProcess option is said to be Win32 only, but it seems working on Linux systems too - please note the IDE version I'm using (on  Windows and Linux) is 1.8.4 as I've not updated the IDE due https://bugs.freepascal.org/view.php?id=35362 bug.

Combining poNewConsole and poWaitOnExit process options in Windows it works as expected: open a console window running the process and showing its output, and wait for the process to complete.

The issue I'm experiencing is that on Linux the behavior is different: a new console window is created and it displays the output of the process, but poWaitOnExit is ignored and the main program immediately continue (eve trying to do something like "while P.running do" etc...).
Both options works fine on Linux, unless you need to use them both for the same process: combining the two options the result is poNewConsole (which documentation says it is not supported) will be applied, and poWaitOnExit (which is supported) will not be applied.

I'm missing something, or there is some known inconsistencies?

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3899
  • I like bugs.
Re: Issue with poNewConsole and poWaitOnExit on Linux
« Reply #1 on: March 08, 2021, 06:24:36 am »
please note the IDE version I'm using (on  Windows and Linux) is 1.8.4 as I've not updated the IDE due https://bugs.freepascal.org/view.php?id=35362 bug.
Martin fixed it in trunk almost a year ago and asked for testing. Does it work there?
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

Jurassic Pork

  • Hero Member
  • *****
  • Posts: 972
Re: Issue with poNewConsole and poWaitOnExit on Linux
« Reply #2 on: March 08, 2021, 06:30:27 am »
hello,
in the documentation poNewConsole TProcess option is said to be Win32 only,
i think it isn't true because in the file process.inc of the folder fpcsrc/packages/fcl-process/src/unix  we can find in the code :
Code: Pascal  [Select][+][-]
  1. if poNewConsole in P.Options then
  2.       begin
to use a terminal to launch and see the target program.
when you do this it seems that the waitonexit doesn't work for the process launched in the terminal.  May be because Terminal launched in background ?
Tested on Ubuntu 20.04  Lazarus 2.1.0 fpc 3.3.1  with this  code :
Code: Pascal  [Select][+][-]
  1. uses process;
  2. {$R *.lfm}
  3. { TForm1 }
  4.  
  5. procedure TForm1.Button1Click(Sender: TObject);
  6. var  hprocess: TProcess;
  7.   begin
  8.   hProcess := TProcess.Create(nil);
  9.   hProcess.Executable := '/bin/bash';
  10.   hprocess.Parameters.Add('read.sh');
  11.   hProcess.Options := hProcess.Options + [poNewConsole,poWaitOnExit];
  12.   hProcess.Execute;
  13.   ShowMessage('end of program');
  14.   hProcess.Free;
  15. end;  
with this in read.sh :
Code: Pascal  [Select][+][-]
  1. #/bin/bash
  2. read toto
  3. echo $toto
the message end of the program is displayed before the end of the bash script.


Friendly,  J.P
« Last Edit: March 08, 2021, 06:52:25 am by Jurassic Pork »
Jurassic computer : Sinclair ZX81 - Zilog Z80A à 3,25 MHz - RAM 1 Ko - ROM 8 Ko

Giorgio Tani

  • New Member
  • *
  • Posts: 21
Re: Issue with poNewConsole and poWaitOnExit on Linux
« Reply #3 on: March 08, 2021, 07:04:09 pm »
Thank you very much for clarification, I'll re-test after updating the IDE on my Linux build machines with latest stable release of Lazaus/FPC.

EDIT: unfortunately, latest published version (Lazarus 2.0.12 with FPC 3.2.0) still have the same problem on Linux machines.
I'm not confident in using a development/test release branch for my builds, so I'll wait the fixes gets into a stable release.
« Last Edit: March 08, 2021, 09:14:42 pm by Giorgio Tani »

 

TinyPortal © 2005-2018