jdk/test/java/lang/ProcessBuilder/Basic.java
changeset 22288 81efc55fac99
parent 22259 8e5afc67dca8
child 22607 ba232b417248
equal deleted inserted replaced
22287:7bb2a658a502 22288:81efc55fac99
    36 import java.lang.ProcessBuilder.Redirect;
    36 import java.lang.ProcessBuilder.Redirect;
    37 import static java.lang.ProcessBuilder.Redirect.*;
    37 import static java.lang.ProcessBuilder.Redirect.*;
    38 
    38 
    39 import java.io.*;
    39 import java.io.*;
    40 import java.lang.reflect.Field;
    40 import java.lang.reflect.Field;
       
    41 import java.nio.file.Files;
       
    42 import java.nio.file.Paths;
       
    43 import java.nio.file.StandardCopyOption;
    41 import java.util.*;
    44 import java.util.*;
    42 import java.util.concurrent.CountDownLatch;
    45 import java.util.concurrent.CountDownLatch;
    43 import java.util.concurrent.TimeUnit;
    46 import java.util.concurrent.TimeUnit;
    44 import java.security.*;
    47 import java.security.*;
    45 import sun.misc.Unsafe;
    48 import sun.misc.Unsafe;
   522             }
   525             }
   523             else throw new Error("JavaChild invocation error");
   526             else throw new Error("JavaChild invocation error");
   524         }
   527         }
   525     }
   528     }
   526 
   529 
   527     private static void copy(String src, String dst) {
   530     private static void copy(String src, String dst) throws IOException {
   528         system("/bin/cp", "-fp", src, dst);
   531         Files.copy(Paths.get(src), Paths.get(dst),
   529     }
   532                    StandardCopyOption.REPLACE_EXISTING, StandardCopyOption.COPY_ATTRIBUTES);
   530 
       
   531     private static void system(String... command) {
       
   532         try {
       
   533             ProcessBuilder pb = new ProcessBuilder(command);
       
   534             ProcessResults r = run(pb.start());
       
   535             equal(r.exitValue(), 0);
       
   536             equal(r.out(), "");
       
   537             equal(r.err(), "");
       
   538         } catch (Throwable t) { unexpected(t); }
       
   539     }
   533     }
   540 
   534 
   541     private static String javaChildOutput(ProcessBuilder pb, String...args) {
   535     private static String javaChildOutput(ProcessBuilder pb, String...args) {
   542         List<String> list = new ArrayList<String>(javaChildArgs);
   536         List<String> list = new ArrayList<String>(javaChildArgs);
   543         for (String arg : args)
   537         for (String arg : args)
  2474     static void unexpected(Throwable t) {failed++; t.printStackTrace();}
  2468     static void unexpected(Throwable t) {failed++; t.printStackTrace();}
  2475     static void check(boolean cond) {if (cond) pass(); else fail();}
  2469     static void check(boolean cond) {if (cond) pass(); else fail();}
  2476     static void check(boolean cond, String m) {if (cond) pass(); else fail(m);}
  2470     static void check(boolean cond, String m) {if (cond) pass(); else fail(m);}
  2477     static void equal(Object x, Object y) {
  2471     static void equal(Object x, Object y) {
  2478         if (x == null ? y == null : x.equals(y)) pass();
  2472         if (x == null ? y == null : x.equals(y)) pass();
  2479         else fail(x + " not equal to " + y);}
  2473         else fail(">'" + x + "'<" + " not equal to " + "'" + y + "'");}
  2480 
  2474 
  2481     public static void main(String[] args) throws Throwable {
  2475     public static void main(String[] args) throws Throwable {
  2482         try {realMain(args);} catch (Throwable t) {unexpected(t);}
  2476         try {realMain(args);} catch (Throwable t) {unexpected(t);}
  2483         System.out.printf("%nPassed = %d, failed = %d%n%n", passed, failed);
  2477         System.out.printf("%nPassed = %d, failed = %d%n%n", passed, failed);
  2484         if (failed > 0) throw new AssertionError("Some tests failed");}
  2478         if (failed > 0) throw new AssertionError("Some tests failed");}