Solved

How do I detect if Java is running in a GUI environment or not?

Posted on 2006-11-06
3
228 Views
Last Modified: 2010-03-31
Hello,
I have a program that I would like to run both from the command line as well as via a gui depending on the environment it is being executed in. How do I detect if java was run from a terminal of some sort, or via a gui?

Worth 500 points.

-Rick
0
Comment
Question by:richardsimnett
  • 2
3 Comments
 
LVL 35

Expert Comment

by:girionis
ID: 17881536
The easiest way is to write this info into a file and then read this file to detect whether the applciation runs from a gui or from command line. Or have a socket that listens to a port and then connect to this port and read the proper information.
0
 
LVL 24

Accepted Solution

by:
sciuriware earned 500 total points
ID: 17881676
I think the only way to detect is via the commandline:
if the program is run from the command line, you can give various arguments, like:

java -jar Program.jar argument1 argument2 ....

if the program is run from another program or from a double click, there is usually no argument on the command line.

This is the way almost all Microsoft and Linux utilities do it.
It's hard to find, but programs like word, excel and powerpoint read their (sometimes) undocumented command line switches,
while clicking an icon will only give a subject filename or drag-and-drop a filename.

;JOOP!
0
 
LVL 24

Expert Comment

by:sciuriware
ID: 17899083
:)
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question