test/java/lang/Runtime/exec/StreamsSurviveDestroy.java

Print this page

        

@@ -100,11 +100,11 @@
 
     static void test() throws Exception {
         CountDownLatch latch = new CountDownLatch(2);
 
         System.err.println("test");
-        Process p = Runtime.getRuntime().exec("/bin/cat");
+        Process p = Runtime.getRuntime().exec(UnixCommands.cat());
         Copier cp1 = new Copier("out", p.getInputStream(), System.err,
                                 false, false, latch);
         Copier cp2 = new Copier("err", p.getErrorStream(), System.err,
                                 false, false, latch);
         latch.await();    // Wait till both Copiers about to read

@@ -120,11 +120,11 @@
 
     static void testCloseBeforeDestroy() throws Exception {
         CountDownLatch latch = new CountDownLatch(2);
 
         System.err.println("testCloseBeforeDestroy");
-        Process p = Runtime.getRuntime().exec("/bin/cat");
+        Process p = Runtime.getRuntime().exec(UnixCommands.cat());
         Copier cp1 = new Copier("out", p.getInputStream(), System.err,
                                 true, false, latch);
         Copier cp2 = new Copier("err", p.getErrorStream(), System.err,
                                 true, false, latch);
         latch.await();    // Wait till both Copiers about to read

@@ -141,11 +141,11 @@
     }
 
     static void testCloseAfterDestroy() throws Exception {
         CountDownLatch latch = new CountDownLatch(2);
         System.err.println("testCloseAfterDestroy");
-        Process p = Runtime.getRuntime().exec("/bin/cat");
+        Process p = Runtime.getRuntime().exec(UnixCommands.cat());
         Copier cp1 = new Copier("out", p.getInputStream(), System.err,
                                 true, false,latch);
         Copier cp2 = new Copier("err", p.getErrorStream(), System.err,
                                 true, false, latch);
 

@@ -163,11 +163,11 @@
     }
 
     static void testInterrupt() throws Exception {
         CountDownLatch latch = new CountDownLatch(2);
         System.err.println("testInterrupt");
-        Process p = Runtime.getRuntime().exec("/bin/cat");
+        Process p = Runtime.getRuntime().exec(UnixCommands.cat());
         Copier cp1 = new Copier("out", p.getInputStream(), System.err,
                                 false, true, latch);
         Copier cp2 = new Copier("err", p.getErrorStream(), System.err,
                                 false, true, latch);
         latch.await();    // Wait till both Copiers about to read

@@ -184,14 +184,17 @@
         cp2.check();
     }
 
     public static void main(String[] args) throws Exception {
 
-        // Applies only to Solaris; Linux and Windows
-        // behave a little differently
-        if (!System.getProperty("os.name").equals("SunOS"))
+        // Applies only to Solaris;
+        // Linux and Windows behave a little differently
+        if (! UnixCommands.isSunOS) {
+            System.out.println("For SunOS only");
             return;
+        }
+        UnixCommands.ensureCommandsAvailable("cat");
 
         test();
         testCloseBeforeDestroy();
         testCloseAfterDestroy();
         testInterrupt();