Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #39653
| From | Knute Johnson <knute2020@585ranch.com> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: Any way to tell on linux if program is started from a terminal? |
| Date | 2020-12-28 20:07 -0600 |
| Organization | A noiseless patient Spider |
| Message-ID | <rse319$qi8$1@dont-email.me> (permalink) |
| References | <rsdjk5$200$1@dont-email.me> <slrnruknd0.2g1.avl@logic.at> |
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());
}
}
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Find similar | Unroll thread
Any way to tell on linux if program is started from a terminal? Knute Johnson <knute2020@585ranch.com> - 2020-12-28 15:44 -0600
Re: Any way to tell on linux if program is started from a terminal? Andreas Leitgeb <avl@logic.at> - 2020-12-28 22:35 +0000
Re: Any way to tell on linux if program is started from a terminal? Knute Johnson <knute2020@585ranch.com> - 2020-12-28 20:07 -0600
csiph-web