Recent

Author Topic: Issue with poNewConsole and poWaitOnExit on Linux  (Read 2677 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: 3961
  • 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: 1035
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 »

devEric69

  • Hero Member
  • *****
  • Posts: 563
Re: Issue with poNewConsole and poWaitOnExit on Linux
« Reply #4 on: September 15, 2021, 04:39:56 pm »
[snip]
Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. var  
  3.   hprocess: TProcess;
  4. begin
  5.   hProcess := TProcess.Create(nil);
  6.   hProcess.Executable := '/bin/bash';
  7.   hprocess.Parameters.Add('read.sh');
  8.   hProcess.Options := hProcess.Options + [poNewConsole, poWaitOnExit];
  9.   hProcess.Execute;
  10.   ShowMessage('end of program');
  11.   hProcess.Free;
  12. end;
with this in read.sh :
Code: [Select]
#/bin/bash
read toto
echo $toto
the message end of the program is displayed before the end of the bash script. Friendly,  J.P

Hello dear all,

I have a question regarding this bug (checked but tested as not fixed on 08 March 2021, by JP). Can someone with the trunk version (i.e. > J.P's Lazarus 2.1.0 fpc 3.3.1), under Linux, test this piece of code and tell me if the showmessage "end of the program" is now displayed after the end of the little bash script in the terminal-bash-window? Thank you very much in advance.

Regards.
use: Linux 64 bits (Ubuntu 20.04 LTS).
Lazarus version: 2.0.4 (svn revision: 62502M) compiled with fpc 3.0.4 - fpDebug \ Dwarf3.

Jurassic Pork

  • Hero Member
  • *****
  • Posts: 1035
Re: Issue with poNewConsole and poWaitOnExit on Linux
« Reply #5 on: September 15, 2021, 05:25:17 pm »
hello,
i just tried with the parameter  XTermProgram for my Tprocess :
Code: Pascal  [Select][+][-]
  1. hProcess.XTermProgram := 'xterm';
it is OK :  end of program is shown only when the xterm is closed.
--> in my case, the default terminal program choosen by Tprocess seemed to be the cause of the problem.
Friendly. J.P
« Last Edit: September 15, 2021, 05:29:01 pm by Jurassic Pork »
Jurassic computer : Sinclair ZX81 - Zilog Z80A à 3,25 MHz - RAM 1 Ko - ROM 8 Ko

devEric69

  • Hero Member
  • *****
  • Posts: 563
Re: Issue with poNewConsole and poWaitOnExit on Linux
« Reply #6 on: September 15, 2021, 06:06:13 pm »
Hello @JP,

Wow! It works on my computer with this setting (hProcess.XTermProgram := 'xterm';) too, i.e. it is really synchronous (nb: after having installed this xterm terminal on my computer; btw, always with an old Lazarus version 2.0.4 + old fpc version 3.0.4). Here is another example (with apt-get update displayed in real time):

Code: Bash  [Select][+][-]
  1. #/bin/bash
  2. echo 'coucou1';
  3. echo 'coucou2';
  4. sudo apt-get update;
  5. read -p "Press any key to continue..." -n1 -s;

Thanks a lot.
« Last Edit: September 17, 2021, 11:30:23 am by devEric69 »
use: Linux 64 bits (Ubuntu 20.04 LTS).
Lazarus version: 2.0.4 (svn revision: 62502M) compiled with fpc 3.0.4 - fpDebug \ Dwarf3.

 

TinyPortal © 2005-2018