Recent

Author Topic: TProcess options under Linux and Mac  (Read 551 times)

simone

  • Sr. Member
  • ****
  • Posts: 378
TProcess options under Linux and Mac
« 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.

« Last Edit: February 28, 2021, 04:02:08 pm by simone »
Microsoft Windows 10 64 bit - Lazarus 2.0.10

ASBzone

  • Hero Member
  • *****
  • Posts: 616
  • Automation leads to relaxation...
    • Free Console Utilities for Windows (and a few for Linux) from BrainWaveCC
Re: TProcess options under Linux and Mac
« Reply #1 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), 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
-ASB: https://www.BrainWaveCC.com/

Lazarus v2.0.13 r64843 / FPC v3.2.1-r49055 (via FpcUpDeluxe) -- Windows 64-bit install w/Win32 and Linux/Arm cross-compiles
Primary System: Windows 10 Pro x64, Version 2009 (Build 19042)
Other Systems: Windows 10 Pro x64, Version 2009 (Build 19042) or greater

simone

  • Sr. Member
  • ****
  • Posts: 378
Re: TProcess options under Linux and Mac
« Reply #2 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.  
Microsoft Windows 10 64 bit - Lazarus 2.0.10

ASBzone

  • Hero Member
  • *****
  • Posts: 616
  • Automation leads to relaxation...
    • Free Console Utilities for Windows (and a few for Linux) from BrainWaveCC
Re: TProcess options under Linux and Mac
« Reply #3 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
-ASB: https://www.BrainWaveCC.com/

Lazarus v2.0.13 r64843 / FPC v3.2.1-r49055 (via FpcUpDeluxe) -- Windows 64-bit install w/Win32 and Linux/Arm cross-compiles
Primary System: Windows 10 Pro x64, Version 2009 (Build 19042)
Other Systems: Windows 10 Pro x64, Version 2009 (Build 19042) or greater

lucamar

  • Hero Member
  • *****
  • Posts: 3927
Re: TProcess options under Linux and Mac
« Reply #4 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.
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

 

TinyPortal © 2005-2018