java - 我如何获得启动该过程的命令行

标签 java command-line environment-variables

从 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/

相关文章:

java - java解析JSON字符串,最佳实践

java - 是否可以保存从字符串迭代中获取的各个字符值?

bash - 用 || 替换新行

linux - 如何在 Linux 命令行上只写入可读文件?显示不可读文件没有权限错误

java - java 方法内多个 ArrayList 初始化可能出现的内存问题

java - 优雅关闭 Java 命令行程序的最佳方法

c - 环境在 Windows 上可用吗?

javascript - Node process.env 变量为空

azure - Powershell - 设置环境变量而无需关闭应用程序

java - 如何从另一个类访问用户定义的 List<> 值?