Solved

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

Posted on 2006-11-06
3
248 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

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…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

724 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