运行exe文件并使用java向其插入一些输入

时间:2017-05-06 05:55:59

标签: java

我在使用java运行exe文件时遇到问题。 exe文件进程是这样​​的:运行命令后它要求 密码,当我插入密码时,它完成了工作。 但在我的java程序中,我试图用exe文件运行一些命令。 我调用exe文件运行我的第一个命令,然后我插入密码与输出流,但t控制台得到freez,它什么也没做。 我的代码:

    String command = "xxxx";
    Process p = Runtime.getRuntime().exec(command);
    BufferedWriter writer = new BufferedWriter(
                new OutputStreamWriter(p.getOutputStream()));
    writer.write("123456");
    writer.close();

    BufferedReader stdInput = new BufferedReader(new
                InputStreamReader(p.getInputStream()));


    BufferedReader stdError = new BufferedReader(new
                InputStreamReader(p.getErrorStream()));

// read the output from the command
        String s = null;
        System.out.println("output of the command:\n");
        while ((s = stdInput.readLine()) != null) {
            System.out.println(s);
        }
// read any errors from the attempted command
        System.out.println(" error of the command (if any):\n");
        while ((s = stdError.readLine()) != null) {
            System.out.println(s);
        }

output

0 个答案:

没有答案
相关问题