Name: mc57594 Date: 02/28/97 1) The Process.waitFor() method sometimes returns before the subprocess has completed. I noticed this when I would sometimes get an exit status of 0 when it should have been 1. I added some System.out.println statements and then saw errors. ################### 2) The code: /** * class: ExecCmd.java * * A class for executing a command line executable. * * @version January 31, 1997 * @author Andy Kowalski * */ import java.io.*; class ExecCmd { // Fields private String cmd; private int i; // Constructor public ExecCmd (String s) { cmd = s; } // Methods public int run () throws InterruptedException, IOException { try { Process child = Runtime.getRuntime().exec(cmd); try { i = child.waitFor(); System.out.println ("waitFor = " + i + " ; " + "exitValue = " + child.exitValue()); return i; } catch (InterruptedException e) { throw e; } } catch (IOException e) { throw e; } } } ###################### 3 and 4) Added new request: /mss/ccc/e96123/raw/50megFileaa false waitFor = 1 ; exitValue = 1 Exit Status = 1 Added new request: /mss/ccc/e96123/raw/50megFileaa false java.lang.IllegalThreadStateException: process hasn't exited at java.lang.UNIXProcess.exitValue(UNIXProcess.java) at ExecCmd.run(ExecCmd.java:34) at TapeReq.run(TapeReq.java:149) ####################### 5) The command (cmd) that I am trying to execute can take minutes to complete. ====================================================================== [chamness 11/27/97] Not clear what command user is trying to execute. The above code snippet has been rewritten to create test case. Bug does not exist in jdk1.1.4 import java.io.*; class execCmd { // Fields private String cmd; private int i; public static void main(String args[]) { execCmd command = new execCmd(args[0]); int result=0; try { result = command.run(); } catch(InterruptedException ie) { System.out.println(ie); } catch(IOException ioe) { System.out.println(ioe); } System.out.println("Result="+result); } // Constructor public execCmd (String s) { cmd = s; } // Methods public int run () throws InterruptedException, IOException { try { Process child = Runtime.getRuntime().exec(cmd); try { i = child.waitFor(); System.out.println ("waitFor = " + i + " ; " + "exitValue = " + child.exitValue()); return i; } catch (InterruptedException e) { throw e; } } catch (IOException e) { throw e; } } }
|