Lazarus

Programming => General => Topic started by: Giorgio Tani on March 07, 2021, 10:30:59 pm

Title: Issue with poNewConsole and poWaitOnExit on Linux
Post by: Giorgio Tani 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?
Title: Re: Issue with poNewConsole and poWaitOnExit on Linux
Post by: JuhaManninen 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?
Title: Re: Issue with poNewConsole and poWaitOnExit on Linux
Post by: Jurassic Pork 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
Title: Re: Issue with poNewConsole and poWaitOnExit on Linux
Post by: Giorgio Tani 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.
TinyPortal © 2005-2018