0
我有一个Java程序与代码:process.exec没有返回正确的代码
public class Test1 {
public static void main(String args[]) throws InterruptedException,
IOException {
String cmd = "cmd /c start test.bat";
Process p = Runtime.getRuntime().exec(cmd);
InputStream stderr = process.getErrorStream();
InputStreamReader isr = new InputStreamReader(stderr);
BufferedReader br = new BufferedReader(isr);
String line = null;
while ((line = br.readLine()) != null){
System.out.println(line);}
p.waitFor();
int exitVal = p.exitValue();
System.out.println(exitVal);
}}
test.bat的执行其它程序具有如下因素代码:
public class ConnectionTest {
public Connection getConn throws SQLException{
Connection conn = null;
Statement st = null;
ResultSet rs = null;
String driverName = "com.ibm.db2.jcc.DB2Driver22222";
try {
Class.forName(driverName).newInstance();
} catch (Exception e) {
e.printStackTrace();
System.exit(1);
}
;;;; ;;;; ;;; ;;;
但是从Test1开始,退出值始终为0.当进入批处理时,它将运行 ConnectionTest类,它将得到异常,因为它不会找到DB2Driver22222。
有人可以向我解释为什么我没有得到正确的错误代码或任何错误消息。
非常感谢... – user234194 2010-08-13 18:02:05