Java - Find out if either a GUI or a CLI is available












2














We have a Java server application which is using YAJSW in order to be run as a windows service. Sometimes the user will be prompted for specific stuff on server startup, such prompting can happen when there is a GUI (via a dialog) or a commandline (via commandline output and input). However, when running as a windows service, there is no way to ask the user for input.



Is there any way to find out if there is no GUI and no CLI available?



As far as I know, GraphicsEnvironment#isHeadless always returns true if a CLI is available, so it will return true when running as a Windows service as well. Therefore I won't be able to distinguish between those two modes.



What I thought I could do, is to simply pass a commandline parameter to the java server application (for example --iswindowsservice) which allows the programmer to distinguish between CLI and windows service mode.



Would there be any better way to solve this problem?










share|improve this question


















  • 1




    When in doubt, that parameter is a valid approach. Alternatively, using an ENV variable or system property would work.
    – GhostCat
    Nov 20 '18 at 14:36










  • Nice idea, a system property actually sounds easier. But I assume there is no built-in way to determine this status without manually passing anything, right?
    – Marcel
    Nov 20 '18 at 14:47










  • If I would know that, I would have written an answer already ;-)
    – GhostCat
    Nov 20 '18 at 14:48










  • Good point, I am little bit slow today ^^
    – Marcel
    Nov 20 '18 at 14:49
















2














We have a Java server application which is using YAJSW in order to be run as a windows service. Sometimes the user will be prompted for specific stuff on server startup, such prompting can happen when there is a GUI (via a dialog) or a commandline (via commandline output and input). However, when running as a windows service, there is no way to ask the user for input.



Is there any way to find out if there is no GUI and no CLI available?



As far as I know, GraphicsEnvironment#isHeadless always returns true if a CLI is available, so it will return true when running as a Windows service as well. Therefore I won't be able to distinguish between those two modes.



What I thought I could do, is to simply pass a commandline parameter to the java server application (for example --iswindowsservice) which allows the programmer to distinguish between CLI and windows service mode.



Would there be any better way to solve this problem?










share|improve this question


















  • 1




    When in doubt, that parameter is a valid approach. Alternatively, using an ENV variable or system property would work.
    – GhostCat
    Nov 20 '18 at 14:36










  • Nice idea, a system property actually sounds easier. But I assume there is no built-in way to determine this status without manually passing anything, right?
    – Marcel
    Nov 20 '18 at 14:47










  • If I would know that, I would have written an answer already ;-)
    – GhostCat
    Nov 20 '18 at 14:48










  • Good point, I am little bit slow today ^^
    – Marcel
    Nov 20 '18 at 14:49














2












2








2







We have a Java server application which is using YAJSW in order to be run as a windows service. Sometimes the user will be prompted for specific stuff on server startup, such prompting can happen when there is a GUI (via a dialog) or a commandline (via commandline output and input). However, when running as a windows service, there is no way to ask the user for input.



Is there any way to find out if there is no GUI and no CLI available?



As far as I know, GraphicsEnvironment#isHeadless always returns true if a CLI is available, so it will return true when running as a Windows service as well. Therefore I won't be able to distinguish between those two modes.



What I thought I could do, is to simply pass a commandline parameter to the java server application (for example --iswindowsservice) which allows the programmer to distinguish between CLI and windows service mode.



Would there be any better way to solve this problem?










share|improve this question













We have a Java server application which is using YAJSW in order to be run as a windows service. Sometimes the user will be prompted for specific stuff on server startup, such prompting can happen when there is a GUI (via a dialog) or a commandline (via commandline output and input). However, when running as a windows service, there is no way to ask the user for input.



Is there any way to find out if there is no GUI and no CLI available?



As far as I know, GraphicsEnvironment#isHeadless always returns true if a CLI is available, so it will return true when running as a Windows service as well. Therefore I won't be able to distinguish between those two modes.



What I thought I could do, is to simply pass a commandline parameter to the java server application (for example --iswindowsservice) which allows the programmer to distinguish between CLI and windows service mode.



Would there be any better way to solve this problem?







java windows windows-services






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 20 '18 at 14:33









MarcelMarcel

555521




555521








  • 1




    When in doubt, that parameter is a valid approach. Alternatively, using an ENV variable or system property would work.
    – GhostCat
    Nov 20 '18 at 14:36










  • Nice idea, a system property actually sounds easier. But I assume there is no built-in way to determine this status without manually passing anything, right?
    – Marcel
    Nov 20 '18 at 14:47










  • If I would know that, I would have written an answer already ;-)
    – GhostCat
    Nov 20 '18 at 14:48










  • Good point, I am little bit slow today ^^
    – Marcel
    Nov 20 '18 at 14:49














  • 1




    When in doubt, that parameter is a valid approach. Alternatively, using an ENV variable or system property would work.
    – GhostCat
    Nov 20 '18 at 14:36










  • Nice idea, a system property actually sounds easier. But I assume there is no built-in way to determine this status without manually passing anything, right?
    – Marcel
    Nov 20 '18 at 14:47










  • If I would know that, I would have written an answer already ;-)
    – GhostCat
    Nov 20 '18 at 14:48










  • Good point, I am little bit slow today ^^
    – Marcel
    Nov 20 '18 at 14:49








1




1




When in doubt, that parameter is a valid approach. Alternatively, using an ENV variable or system property would work.
– GhostCat
Nov 20 '18 at 14:36




When in doubt, that parameter is a valid approach. Alternatively, using an ENV variable or system property would work.
– GhostCat
Nov 20 '18 at 14:36












Nice idea, a system property actually sounds easier. But I assume there is no built-in way to determine this status without manually passing anything, right?
– Marcel
Nov 20 '18 at 14:47




Nice idea, a system property actually sounds easier. But I assume there is no built-in way to determine this status without manually passing anything, right?
– Marcel
Nov 20 '18 at 14:47












If I would know that, I would have written an answer already ;-)
– GhostCat
Nov 20 '18 at 14:48




If I would know that, I would have written an answer already ;-)
– GhostCat
Nov 20 '18 at 14:48












Good point, I am little bit slow today ^^
– Marcel
Nov 20 '18 at 14:49




Good point, I am little bit slow today ^^
– Marcel
Nov 20 '18 at 14:49












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53395306%2fjava-find-out-if-either-a-gui-or-a-cli-is-available%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53395306%2fjava-find-out-if-either-a-gui-or-a-cli-is-available%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

"Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

Alcedinidae

Origin of the phrase “under your belt”?