• Any way to tell on linux if program is started from a terminal?

    From Knute Johnson@21:1/5 to All on Mon Dec 28 15:44:37 2020
    Any way to tell on linux if a program is started from a terminal versus
    started from clicking on an icon?

    Thanks,

    knute

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Andreas Leitgeb@21:1/5 to Knute Johnson on Mon Dec 28 22:35:12 2020
    Knute Johnson <knute2020@585ranch.com> wrote:
    Any way to tell on linux if a program is started from a terminal versus started from clicking on an icon?

    Maybe https://docs.oracle.com/en/java/javase/11/docs/api/java.desktop/java/awt/GraphicsEnvironment.html#isHeadless()

    or
    https://docs.oracle.com/javase/7/docs/api/java/lang/System.html#console() (compare result with null)

    depending on what you want to get if both console and X11 is available.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Knute Johnson@21:1/5 to Andreas Leitgeb on Mon Dec 28 20:07:35 2020
    On 12/28/20 4:35 PM, Andreas Leitgeb wrote:
    Knute Johnson <knute2020@585ranch.com> wrote:
    Any way to tell on linux if a program is started from a terminal versus
    started from clicking on an icon?

    Maybe https://docs.oracle.com/en/java/javase/11/docs/api/java.desktop/java/awt/GraphicsEnvironment.html#isHeadless()

    or
    https://docs.oracle.com/javase/7/docs/api/java/lang/System.html#console() (compare result with null)

    depending on what you want to get if both console and X11 is available.


    The Console test worked perfectly, thanks Andreas! Here is my test
    program if anybody is interested. Tested on Xubuntu 20.10 and
    RaspberryPi OS.

    import java.awt.*;
    import java.awt.event.*;
    import java.io.*;
    import javax.swing.*;

    public class test5 extends JFrame {
    public test5() {
    super("test5");

    setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

    Console c = System.console();
    JLabel l = new JLabel(c==null ? "null" :
    c.toString(),JLabel.CENTER);
    add(l,BorderLayout.CENTER);

    setSize(400,300);
    setLocationRelativeTo(null);
    setVisible(true);
    }

    public static void main(String... args) {
    EventQueue.invokeLater(() -> new test5());
    }
    }

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)