app from terminal or gui? [SOLVED]

Post your Gambas programming questions here.
Post Reply
User avatar
BruceSteers
Posts: 652
Joined: Thursday 23rd July 2020 5:20pm

app from terminal or gui? [SOLVED]

Post by BruceSteers » Monday 28th June 2021 6:33pm

Does anyone know if there is a sure fire way of telling if an app has been launched via terminal or gui?

basically i ned to provide shell output to the user and the app could be launched from terminal or desktop drag n drop (or other methods that may not have a terminal)

So my plan is to output to stdout if launched via a terminal or open a form with a terminalview if not.

But how to tell the difference?

Cheers in advance for any advice.
:)
Last edited by BruceSteers on Tuesday 29th June 2021 9:49am, edited 1 time in total.
Wishing well
Bruce

If at first you don't succeed , try it differently.

User avatar
PJBlack
Posts: 159
Joined: Tuesday 09th June 2020 10:26pm
Location: Florstadt, Hessen, Germany

Re: app from terminal or gui?

Post by PJBlack » Tuesday 29th June 2021 12:10am

MAYBE something like so:
    Try Debug Me.h

    If Not Error Then Debug "GUI Programm ..." Else Debug "Konsolenprogramm ..."

User avatar
BruceSteers
Posts: 652
Joined: Thursday 23rd July 2020 5:20pm

Re: app from terminal or gui?

Post by BruceSteers » Tuesday 29th June 2021 8:19am

PJBlack wrote:
Tuesday 29th June 2021 12:10am
MAYBE something like so:
    Try Debug Me.h

    If Not Error Then Debug "GUI Programm ..." Else Debug "Konsolenprogramm ..."
Cheers, but alas that's no good.
The application starts from a startup class not a form so none of the usual Me. things exist.

also if no args it loads it's gui otherwise it runs the shell command so it usually will not have a gui window open.
Wishing well
Bruce

If at first you don't succeed , try it differently.

User avatar
BruceSteers
Posts: 652
Joined: Thursday 23rd July 2020 5:20pm

Re: app from terminal or gui?

Post by BruceSteers » Tuesday 29th June 2021 9:15am

Many Thanks to Tobias Boege on the Gambas m/l for this reply...

If anyone else want's the answer to the question.....
File.In.IsTerm is true if and only if the standard input of your program
is connected to a (pseudo) terminal. This will be the case when you launch
the program in a terminal emulator. It will also be the case if you launch
it in the IDE (because it is connected to the TerminalView in the IDE).
It will be false if you launch it via double click from your desktop.
Wishing well
Bruce

If at first you don't succeed , try it differently.

Post Reply