JavaFx - 我需要执行db2cw.bat驱动程序,然后执行
我在代码中使用了Processbuilder。 db2cw.bat从目录cwd
成功打开,并执行dbc
命令以连接到DB2。但是下一个命令因IO异常而失败。我应该如何将Export命令传递给命令行?
java.io.IOException: The pipe is being closed
代码
List<String> list = new ArrayList<String>();
list.add(cmd); // path to db2cw.bat
list.add(dbc); // path to .cmd file for DB2 connection
list.add(exp); // path to db2EXPORT command
ProcessBuilder builder = new ProcessBuilder(list);
Process p = null;
builder.directory(new File(cwd));
try {
p = builder.start();
p.waitFor();
} catch (IOException e) {
System.out.println(e);
}
//get stdin of shell
BufferedWriter p_stdin = new BufferedWriter(new OutputStreamWriter(p.getOutputStream()));
try {
p_stdin.write(exp);
System.out.println(cwd);
p_stdin.newLine();
p_stdin.flush();
} catch (IOException e) {
System.out.println(e);
System.out.println("Export Error");
}
try {
p_stdin.write("exit");
p_stdin.newLine();
p_stdin.flush();
} catch (IOException e) {
System.out.println(e);
System.out.println("Exit Error");
}
} catch (Exception e) {
e.printStackTrace();
}