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.
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.
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.
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.)