Java 9 provied pretty way to get information of the Process
, but I still don't know how to get the CommandLine
& arguments
of the process:
Process p = Runtime.getRuntime().exec("notepad.exe E:\\test.txt");
ProcessHandle.Info info = p.toHandle().info();
String[] arguments = info.arguments().orElse(new String[]{});
System.out.println("Arguments : " + arguments.length);
System.out.println("Command : " + info.command().orElse(""));
System.out.println("CommandLine : " + info.commandLine().orElse(""));
Result:
Arguments : 0
Command : C:\Windows\System32\notepad.exe
CommandLine :
But I am expecting:
Arguments : 1
Command : C:\Windows\System32\notepad.exe
CommandLine : C:\Windows\System32\notepad.exe E:\\test.txt