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

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

问题描述



System.getEnv()

从Java中获取完整的命令行, code>和 System.getProperties()看起来不包含值。

解决方案

其中一些可从RuntimeMXBean获得,通过调用 ManagementFactory.getRuntimeMXBean()



然后,您可以调用 getInputArguments()



javadocs:


返回传递给Java虚拟机的输入参数,它不包括main方法的参数。



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



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



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

System.getEnv() and System.getProperties() do not appear to contain the values.

解决方案

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

You can then, for example call getInputArguments()

The javadocs for which say:

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.

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

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