1

I have java 1.4 console project myPro in Ubuntu Linux. How to know what command was used to start myPro from inside of java project?

I need this for startup script update reason.

3
  • 2
    One question: why do you need this information? It looks like another example of XY problem. Commented Sep 7, 2015 at 14:43
  • Are you interested in some specific informations from command? Commented Sep 7, 2015 at 14:58
  • i need to know which script started programm Commented Sep 7, 2015 at 15:46

2 Answers 2

1

The simplest solution, though slightly rough, is to send this information as an argument to your project and receive it in the main method. Otherwise, you need to reach out for Linux history or some invoking process identifier.

Here you can read a bit about getting last command run in bash script, if that's what you want. BASH: echoing the last command run You'll easily find yourself how to call bash from Java.

Sign up to request clarification or add additional context in comments.

Comments

0

If you meant the equivalent of $0 in shell scripts, I don't think there is a standardized way of getting it. The virtual machine abstracts it away.

However, if you are using Oracle JRE, try System.getProperty("sun.java.command"). Could be a second best choice.

If your Java program is wrapped in a shell script, you could read $* from there and pass it to the Java world through a -D option. (I did this in an old project where the full command line was needed to be logged from Java space.)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.