Created
April 4, 2026 17:37
-
-
Save ahndmal/f1325aff7adbdf70174e63dbd77ca76e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public static void getInfoTest() throws IOException { | |
| ProcessBuilder pb = new ProcessBuilder("echo", "Hello World!"); | |
| String na = "<not available>"; | |
| Process p = pb.start(); | |
| ProcessHandle.Info info = p.info(); | |
| System.out.printf("Process ID: %s%n", p.pid()); | |
| System.out.printf("Command name: %s%n", info.command().orElse(na)); | |
| System.out.printf("Command line: %s%n", info.commandLine().orElse(na)); | |
| System.out.printf("Start time: %s%n", | |
| info.startInstant().map((Instant i) -> i | |
| .atZone(ZoneId.systemDefault()).toLocalDateTime().toString()) | |
| .orElse(na)); | |
| System.out.printf("Arguments: %s%n", | |
| info.arguments().map( | |
| (String[] a) -> Stream.of(a).collect(Collectors.joining(" "))) | |
| .orElse(na)); | |
| System.out.printf("User: %s%n", info.user().orElse(na)); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment