?
Solved

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

Posted on 2006-11-06
3
Medium Priority
?
251 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 2000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
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…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
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:
Suggested Courses
Course of the Month12 days, 7 hours left to enroll

777 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