We have a program with a main() that parses certain CLPs but does not save them anywhere.
I then have my own plug-in code that needs access to the original CLPs (so I can transmit more parameters) for it. However, I cannot change main()
I saw that there is apparently a way to do this in C#, I’m looking for an equivalent Java solution on Linux.
UPDATE: Obviously, I’m aware of how main() works. Unfortunately, I cannot change the existing application or the way it is invoked (except for CLPs). I can only access via a sandboxed plugin code. My question is whether there is a way to get the command line (rather then the environment variables with -D) that the JVM was invoked with.
Apart from doing it in main in some way I think the only other option that you have would be to drop to the operating system level and execute some commands to get the arguments.
On linux the cmd line arguments for a running process are stored at /proc/pid/cmdline
So to get them you would have to find the process id. See here:
How can a Java program get its own process ID?
Then using this open /proc/pid/cmdline and parse it. The format of this file and an example in c is here:
http://www.unix.com/unix-advanced-expert-users/86740-retrieving-command-line-arguments-particular-pid.html
It might be best to wrap these two calls in one shell script that you call from java.
Please note that this will be extremely non portable and is a bit hacky. But if needs must…