Solved

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

Posted on 2006-11-06
3
209 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
Comment Utility
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
Comment Utility
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
Comment Utility
:)
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
changeXy challenge 13 55
network + 7 72
topping3 challenge 14 48
bitbucket vs gitbucket 3 28
For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
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…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…

728 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now