< prev index next >

test/java/lang/ProcessHandle/JavaChild.java

Print this page
rev 12532 : 8131168: Refactor ProcessHandleImpl_*.c and add implememtation for AIX
Reviewed-by: rriggs, smarks

@@ -66,12 +66,13 @@
      * Create a JavaChild control instance that delegates to the spawned process.
      * {@link #sendAction} is used to send commands via the processes stdin.
      * {@link #forEachOutputLine} can be used to process output from the child
      * @param delegate the process to delegate and send commands to and get responses from
      */
-    private JavaChild(Process delegate) {
-        this.delegate = delegate;
+    private JavaChild(ProcessBuilder pb) throws IOException {
+        allArgs = pb.command();
+        delegate = pb.start();
         // Initialize PrintWriter with autoflush (on println)
         inputWriter = new PrintWriter(delegate.getOutputStream(), true);
         outputReader = new BufferedReader(new InputStreamReader(delegate.getInputStream()));
     }
 

@@ -117,10 +118,14 @@
     @Override
     public String toString() {
         return "delegate: " + delegate.toString();
     }
 
+    public List<String> getArgs() {
+        return allArgs;
+    }
+
     public CompletableFuture<JavaChild> onJavaChildExit() {
         return onExit().thenApply(ph -> this);
     }
 
     /**

@@ -185,11 +190,11 @@
         for (int i = 0; i < args.length; i++) {
             stringArgs[i] = args[i].toString();
         }
         ProcessBuilder pb = build(stringArgs);
         pb.redirectError(ProcessBuilder.Redirect.INHERIT);
-        return new JavaChild(pb.start());
+        return new JavaChild(pb);
     }
 
     /**
      * Spawn a JavaChild with the provided arguments.
      * Sets the process to inherit the I/O channels.

@@ -234,10 +239,13 @@
                     "-XX:+DisplayVMOutputToStderr",
                     "-Dtest.jdk=" + javaHome,
                     "-classpath", absolutifyPath(classpath),
                     "JavaChild");
 
+    // Will hold the complete list of arguments which was given to Processbuilder.command()
+    private List<String> allArgs;
+
     private static String absolutifyPath(String path) {
         StringBuilder sb = new StringBuilder();
         for (String file : path.split(File.pathSeparator)) {
             if (sb.length() != 0)
                 sb.append(File.pathSeparator);
< prev index next >