Lazarus

Programming => General => Topic started by: simone on February 28, 2021, 01:59:17 pm

Title: TProcess options under Linux and Mac
Post by: simone on February 28, 2021, 01:59:17 pm
I am writing a cross-platform application that uses the TProcess class and its Options intensively. I have developed and tested the application under Windows and there are no problems. Since I use options available only under Windows platform (according to the following documentation https://lazarus-ccr.sourceforge.io/docs/fcl/process/tprocess.options.html), in particular poNewConsole, I ask you if and how it is possible to obtain behavior related to options for Windows, also on other platforms. Thanks in advance.

Title: Re: TProcess options under Linux and Mac
Post by: ASBzone on February 28, 2021, 04:58:51 pm
I am writing a cross-platform application that uses the TProcess class and its Options intensively. I have developed and tested the application under Windows and there are no problems. Since I use options available only under Windows platform (according to the following documentation https://lazarus-ccr.sourceforge.io/docs/fcl/process/tprocess.options.html (https://lazarus-ccr.sourceforge.io/docs/fcl/process/tprocess.options.html)), in particular poNewConsole, I ask you if and how it is possible to obtain behavior related to options for Windows, also on other platforms. Thanks in advance.

The answer to your question might require us to know what processes you are looking to spawn in Linux/Mac.

Also, have you seen this?  https://wiki.freepascal.org/Executing_External_Programs
Title: Re: TProcess options under Linux and Mac
Post by: simone on February 28, 2021, 07:25:53 pm
Consider the following two programs: Project2 launches Project1 in a different console under Windows, with the option 'poNewConsole'. But the documentation says "Win32 only". Can I get the same under Linux and Mac?

Code: Pascal  [Select][+][-]
  1. program project1;
  2.  
  3. begin
  4.   writeln('ok');
  5.   readln;
  6. end.
  7.  

Code: Pascal  [Select][+][-]
  1. program project2;
  2. uses
  3.   Process;
  4.  
  5. begin
  6.   with TProcess.Create(nil) do
  7.     begin
  8.       Options:=Options+[poNewConsole]; //only for win32. under linux and mac?
  9.       Executable:='project1.exe';
  10.       Execute;
  11.       Free;
  12.     end;
  13.   readln;
  14. end.
  15.  
Title: Re: TProcess options under Linux and Mac
Post by: ASBzone on February 28, 2021, 07:48:00 pm
I believe that a separate console should be instantiated on Linux for each TProcess call, by default.  I am not able to test that right now, though.

Thanks for the test code.

BTW, have you see this?  https://kriscode.blogspot.com/2018/02/console-vs-gui-application-in-op.html (https://kriscode.blogspot.com/2018/02/console-vs-gui-application-in-op.html)
Title: Re: TProcess options under Linux and Mac
Post by: lucamar on February 28, 2021, 10:34:39 pm
I believe that a separate console should be instantiated on Linux for each TProcess call, by default.

Most, if not all, Unix-like and Unix-derived OS* (as indeed most multi-user systems) can usually run any program/process whether there is a console or not, so whether it's there is up to you (or the user). Which means that running an external process doesn't spawn a terminal session by itself and there are no "standard" facilities to do so.

The common solution (in modern Pascal programs) is to either build your own "teminal" (either an internal or embeded emulator) and link its IO to the process's or run your process as a "command" for the choosen terminal "emulator" (gnome-terminal, xfce4-terminal, etc.) Not really difficult, but neither it's a pice of cake, much less to make it perform seamlessly across several different distros/systems.


* Like e.g. modern Macos, which is based in BSD Unix.
TinyPortal © 2005-2018