的Java 9 provied漂亮的方式来获得Process
的信息,但我还是不知道怎么弄的过程中CommandLine
& arguments
:如何获得命令行及工艺过程处理的参数在Java中9
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(""));
结果:
Arguments : 0
Command : C:\Windows\System32\notepad.exe
CommandLine :
但我期待:
Arguments : 1
Command : C:\Windows\System32\notepad.exe
CommandLine : C:\Windows\System32\notepad.exe E:\\test.txt
只是为了进一步调试,是否可以尝试用ProcessHandle.current()替换ProcessHandler的'p.toHandle()'并执行以查看,如果在预期的字段中获得了一些值?大部分的兴趣是看你的当前进程的进程处理器是否合适。 – nullpointer
不幸运,仍然是一样的。 – Jerry06