Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #39651 > unrolled thread
| Started by | Knute Johnson <knute2020@585ranch.com> |
|---|---|
| First post | 2020-12-28 15:44 -0600 |
| Last post | 2020-12-28 20:07 -0600 |
| Articles | 3 — 2 participants |
Back to article view | Back to comp.lang.java.programmer
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
| From | Knute Johnson <knute2020@585ranch.com> |
|---|---|
| Date | 2020-12-28 15:44 -0600 |
| Subject | Any way to tell on linux if program is started from a terminal? |
| Message-ID | <rsdjk5$200$1@dont-email.me> |
Any way to tell on linux if a program is started from a terminal versus started from clicking on an icon? Thanks, knute
[toc] | [next] | [standalone]
| From | Andreas Leitgeb <avl@logic.at> |
|---|---|
| Date | 2020-12-28 22:35 +0000 |
| Message-ID | <slrnruknd0.2g1.avl@logic.at> |
| In reply to | #39651 |
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.
[toc] | [prev] | [next] | [standalone]
| From | Knute Johnson <knute2020@585ranch.com> |
|---|---|
| Date | 2020-12-28 20:07 -0600 |
| Message-ID | <rse319$qi8$1@dont-email.me> |
| In reply to | #39652 |
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());
}
}
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.java.programmer
csiph-web