我在使用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);
}