用于连接和执行db2命令的JavaFX

时间:2016-08-19 09:58:21

标签: java db2 javafx-8 processbuilder

JavaFx - 我需要执行db2cw.bat驱动程序,然后执行

  1. 更改目录
  2. 执行.cmd文件
  3. 执行db2 EXPORT命令
  4. 处理完导出后,关闭窗口
  5. 我在代码中使用了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();
        }
    

0 个答案:

没有答案