0

Is there a way in Java to identify if the program is being triggered from the command prompt?

I know when a C# program is triggered from CMD, it sets RUN_FROM_CMD environment variable to TRUE and can be identified using the below line of code, but the same does not work in Java.

Environment.GetEnvironmentVariable("RUN_FROM_CMD")

Please Suggest a way, if there is any.

Appu Mistri
  • 768
  • 8
  • 26
  • I cannot find any information about `RUN_FROM_CMD` variable, where did you get that info? – Iłya Bursov Aug 30 '18 at 20:14
  • I am currently using `RUN_FROM_CMD` variable for one of my C# test projects, to determine if the program is being triggered from CMD. – Appu Mistri Aug 30 '18 at 20:16
  • `System.getenv("RUN_FROM_CMD");` will do the same thing as your C# snippet. Good luck! – Elliott Frisch Aug 30 '18 at 20:18
  • @ElliottFrisch I tested this out, it returns `null` in both the cases, when I run it from Eclipse and when I run it from CMD. – Appu Mistri Aug 30 '18 at 20:31
  • @AppuMistri I said it does the same thing as your C# snippet. Do you run your C# code in eclipse? Because if you did, it would be `null` there too. Likewise, when you run your C# code on the command line, what is setting that environment variable? – Elliott Frisch Aug 30 '18 at 20:50
  • 1
    @ElliottFrisch No, I run my C# projects on Visual Studio or Jenkins. Likewise, for Java projects, I use Eclipse or Jenkins. It could be `MSBuild` (Which is being used to build and run my C# code) that sets the environment variable, but I'm really not sure about that. However, this [answer](https://stackoverflow.com/a/51817842/6513289) workes for me. – Appu Mistri Aug 30 '18 at 21:24

0 Answers0