[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

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

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

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
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 about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Suggested Courses

649 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