从 Java 中,是否有可能获得包含启动应用程序的所有参数的完整命令行?
System.getEnv()
和 System.getProperties()
似乎不包含这些值。
最佳答案
其中一些可从 RuntimeMXBean 获得,通过调用 ManagementFactory.getRuntimeMXBean()
获得
然后您可以调用 getInputArguments()
javadocs 说:
Returns the input arguments passed to the Java virtual machine which does not include the arguments to the main method. This method returns an empty list if there is no input argument to the Java virtual machine.
Some Java virtual machine implementations may take input arguments from multiple different sources: for examples, arguments passed from the application that launches the Java virtual machine such as the 'java' command, environment variables, configuration files, etc.
Typically, not all command-line options to the 'java' command are passed to the Java virtual machine. Thus, the returned input arguments may not include all command-line options.
关于java - 我如何获得启动该过程的命令行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2541627/