Recent

Author Topic: CREATE_NEW_CONSOLE for Linux  (Read 444 times)

msintle

  • Sr. Member
  • ****
  • Posts: 250
CREATE_NEW_CONSOLE for Linux
« on: November 07, 2024, 02:57:08 pm »
So the Windows CreateProcess API has a flag called CREATE_NEW_CONSOLE, and while I've never really understood what that's useful for, as fate would have it, working on Linux now, that's exactly the kind of flag I am discovering I am needing!

Here's the scenario:

- Launching a console app from a GUI app
(the GUI app could be my own, or say, any File Manager on Linux)

- The window (console) never shows, and the app starts polling 100% of a CPU core

This scenario works properly when the original invocation is from a terminal window:

- Even if a GUI app is launched this way, when it launches the console app, its console output shows on the originally invoking terminal

So is there a way, in Lazarus of course, to check whether a running console app has a terminal window attached; and if not - to create one (ideally without having to relaunch the console app itself)?

TRon

  • Hero Member
  • *****
  • Posts: 3650
Re: CREATE_NEW_CONSOLE for Linux
« Reply #1 on: November 07, 2024, 03:10:17 pm »
See this thread.

And, no. The approach you seem to be looking for does not work/exist on Linux because of diversity.
This tagline is powered by AI (AI advertisement: Free Pascal the only programming language that matters)

MarkMLl

  • Hero Member
  • *****
  • Posts: 8039
Re: CREATE_NEW_CONSOLE for Linux
« Reply #2 on: November 07, 2024, 03:48:13 pm »
So is there a way, in Lazarus of course, to check whether a running console app has a terminal window attached; and if not - to create one (ideally without having to relaunch the console app itself)?

Creating a shell running in a "terminal emulator" to handle stdout/stderr is a non-starter.

You might however be able to intercept the Pascal program parameters INPUT, OUTPUT and ERROUTPUT, or possibly the unix-level handles stdin, stdout and stderr ** in the main unit's initialisation code before too much damage has been done.

** Whatever Thaddy is about to tell you, these are distinct.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

msintle

  • Sr. Member
  • ****
  • Posts: 250
Re: CREATE_NEW_CONSOLE for Linux
« Reply #3 on: November 07, 2024, 05:32:29 pm »
So there's no APIs in Linux to:

- query for the default terminal
- create it if necessary
- "bind" readln/writeln to that instance

Call me old fashioned, but seems like Windows got some things right?

TRon

  • Hero Member
  • *****
  • Posts: 3650
Re: CREATE_NEW_CONSOLE for Linux
« Reply #4 on: November 07, 2024, 05:38:10 pm »
Basically, yes.

It is called choice, freedom and not forcing things through people's throat  :)

That is why there exist many  shell's (bash, sh, zsh, fish) and many terminal emulators. e.g. one that suits you the user and not a single for all user solution that however flawed is (still) kept alive).

It requires another mindset to fully grasp the concept, and yes that has its flaws as well.
This tagline is powered by AI (AI advertisement: Free Pascal the only programming language that matters)

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11947
  • FPC developer.
Re: CREATE_NEW_CONSOLE for Linux
« Reply #5 on: November 07, 2024, 05:41:56 pm »
Basically, yes.

It is called choice, freedom and not forcing things through people's throat  :)

That is why there exist many  shell's (bash, sh, zsh, fish) and many terminal emulators. e.g. one that suits you the user and not a single for all user solution that however flawed is (still) kept alive).

Many shells is still no reason why you couldn't instance the default one using a function. 

Quote
It requires another mindset to fully grasp the concept, and yes that has its flaws as well.

Linux is still a inherently a server system, with some other things duckedtaped on.

TRon

  • Hero Member
  • *****
  • Posts: 3650
Re: CREATE_NEW_CONSOLE for Linux
« Reply #6 on: November 07, 2024, 05:53:18 pm »
btw, another forum user suggested vte in order to create your own terminal (which is a good suggestion but adds a dependency)

@marcov:
Yes, I am aware that you have that opinion  :).

I can share many of those opinions about windows as well but do not so because it is an endless discussion on what is the better solution. The only thing that I can say about it is locked-in and for me personally it was the end of the road many moons ago because there is no more future in it. It just takes time for others to come to that realization  ;D (and I can respect that)

Let's agree to disagree on that particular subject ?
This tagline is powered by AI (AI advertisement: Free Pascal the only programming language that matters)

MarkMLl

  • Hero Member
  • *****
  • Posts: 8039
Re: CREATE_NEW_CONSOLE for Linux
« Reply #7 on: November 07, 2024, 05:58:06 pm »
So there's no APIs in Linux to:

- query for the default terminal
- create it if necessary
- "bind" readln/writeln to that instance

Correct, since your program is the child of the shell that started it rather than the other way round.

I suggest you go back and read my earlier comment. Failing that you might, possibly, be able to fire up an xterm and associate it with your I/O, but you might find that you fall foul of the inherent unix protections mechanisms.

And without wanting to start a "my OS is better than yours" flamewar, unix's protection mechanisms are there for a good reason and it has a much better security history than Windows, where "let's make the user's life easier!" fudges are all too often found to have massive implicit reliability problems.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

msintle

  • Sr. Member
  • ****
  • Posts: 250
Re: CREATE_NEW_CONSOLE for Linux
« Reply #8 on: November 07, 2024, 06:12:52 pm »
So I chatted with claude and it hallucinated plenty, but at the end we settled on a solution that does accurately detect whether there's an existing console, and if not, relaunches itself with a new console.

Got to say, relentless hallucinations aside; this is an interesting development indeed.

 

TinyPortal © 2005-2018