test/java/lang/Runtime/exec/ExecWithInput.java

Print this page

        

@@ -37,23 +37,23 @@
  * Linux or other OSes, or server JVM.
  */
 
 public class ExecWithInput {
 
-    private static final String CAT = "/bin/cat";
+    static final boolean isLinux =
+            System.getProperty("os.name", "unknown").startsWith("Linux");
     private static final int N = 200;
 
     static int go(int i) throws Exception {
         /*
          * Execute /bin/cat supplying two lines of input. cat should
          * read the input lines and copy them to stdout. On completion,
          * p.waitFor should return and the exit status is printed and this
          * program exits. Under 1.4.1, cat sometimes gets stuck on a pipe
          * read and never terminates.
          */
-        //Process p = Runtime.getRuntime().exec(new String[] { CAT } );
-        Process p = Runtime.getRuntime().exec(CAT);
+        Process p = Runtime.getRuntime().exec("cat");
 
         String input = i + ": line 1\n" + i + ": line 2\n";
         StringBufferInputStream in = new StringBufferInputStream(input);
         // create threads to handle I/O streams
         IO ioIn = new IO("stdin", in, p.getOutputStream());

@@ -63,14 +63,12 @@
         // wait for process to exit
         return p.waitFor();
     }
 
     public static void main(String[] args) throws Exception {
-        if (!System.getProperty("os.name").equals("Linux"))
-            return;
-        if (File.separatorChar == '\\') {
-            // no /bin/cat on windows
+        if (! isLinux) {
+            System.err.println("Only for Linux");
             return;
         }
         for (int i = 0; i < N; i++)
             go(i);
     }