如何获取启动该过程的命令行 [英] How do I get the commandline that started the process

查看:97
本文介绍了如何获取启动该过程的命令行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从Java开始,可以得到带有启动应用程序的所有参数的完整命令行?

From Java, is it possible to get the complete commandline with all arguments that started the application?

System.getEnv() code>和 System.getProperties()不会包含这些值。

推荐答案

其中一些可通过调用 ManagementFactory.getRuntimeMXBean()

Some of it is available from the RuntimeMXBean, obtained by calling ManagementFactory.getRuntimeMXBean()

你然后,可以调用 getInputArguments()

You can then, for example call getInputArguments()

javadocs说:

The javadocs for which say:


返回传递给Java虚拟机的输入参数,该虚拟机不包含main方法的参数。如果Java虚拟机没有输入参数,则此方法返回一个空列表。

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.

某些Java虚拟机实现可能会从多个不同的来源获取输入参数:例如,从启动Java虚拟机的应用程序传递的参数,如java命令,环境变量,配置文件等。

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.

通常,并不是所有的命令行选项到'java'命令传递给Java虚拟机。因此,返回的输入参数可能不包括所有命令行选项。

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.

这篇关于如何获取启动该过程的命令行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆