< prev index next >

test/jdk/java/lang/ProcessBuilder/DestroyTest.java

Print this page
rev 59383 : [mq]: final
   1 /*
   2  * Copyright (c) 2012, 2019, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */


  96     public WindowsTest() throws IOException {
  97         bldr = new ProcessBuilder("ftp");
  98         bldr.redirectErrorStream(true);
  99         bldr.directory(new File("."));
 100         p = bldr.start();
 101     }
 102 
 103 }
 104 
 105 public class DestroyTest {
 106 
 107     public static ProcessTest getTest() throws Exception {
 108         String osName = System.getProperty("os.name");
 109         if (osName.startsWith("Windows")) {
 110             return new WindowsTest();
 111         } else {
 112             File userDir = new File(System.getProperty("user.dir", "."));
 113             File tempFile = File.createTempFile("ProcessTrap-", ".sh", userDir);
 114             if (osName.startsWith("Linux")
 115                     || osName.startsWith("Mac OS")
 116                     || osName.equals("SunOS")
 117                     || osName.equals("AIX")) {
 118                 return new UnixTest(tempFile);
 119             }
 120         }
 121         return null;
 122     }
 123 
 124     public static void main(String args[]) throws Exception {
 125         ProcessTest test = getTest();
 126         if (test == null) {
 127             throw new RuntimeException("Unrecognised OS");
 128         } else {
 129             new Thread(test).start();
 130             Thread.sleep(1000);
 131             test.runTest();
 132         }
 133     }
 134 }
 135 
   1 /*
   2  * Copyright (c) 2012, 2020, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */


  96     public WindowsTest() throws IOException {
  97         bldr = new ProcessBuilder("ftp");
  98         bldr.redirectErrorStream(true);
  99         bldr.directory(new File("."));
 100         p = bldr.start();
 101     }
 102 
 103 }
 104 
 105 public class DestroyTest {
 106 
 107     public static ProcessTest getTest() throws Exception {
 108         String osName = System.getProperty("os.name");
 109         if (osName.startsWith("Windows")) {
 110             return new WindowsTest();
 111         } else {
 112             File userDir = new File(System.getProperty("user.dir", "."));
 113             File tempFile = File.createTempFile("ProcessTrap-", ".sh", userDir);
 114             if (osName.startsWith("Linux")
 115                     || osName.startsWith("Mac OS")

 116                     || osName.equals("AIX")) {
 117                 return new UnixTest(tempFile);
 118             }
 119         }
 120         return null;
 121     }
 122 
 123     public static void main(String args[]) throws Exception {
 124         ProcessTest test = getTest();
 125         if (test == null) {
 126             throw new RuntimeException("Unrecognised OS");
 127         } else {
 128             new Thread(test).start();
 129             Thread.sleep(1000);
 130             test.runTest();
 131         }
 132     }
 133 }
 134 
< prev index next >