Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get the commandline that started the process

Tags:

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.

like image 320
aksamit Avatar asked Mar 29 '10 22:03

aksamit


People also ask

What is the command to find out the current running processes?

You can use the ps command to find out which processes are running and display information about those processes. The ps command has several flags that enable you to specify which processes to list and what information to display about each process.

What is the command line of the process?

Command line refers to the arguments that are passed to an executable process in Windows. It is useful information for defenders as it can reveal contextual clues about the execution of a suspicious process.

How do I run a Windows process from the command line?

Type "start [filename.exe]" into Command Prompt, replacing "filename" with the name of your selected file. Replace "[filename.exe]" with your program's name. This allows you to run your program from the file path.


1 Answers

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.

like image 125
Stephen Denne Avatar answered Oct 05 '22 23:10

Stephen Denne