Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/395.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在Windows中输入并从控制台获取返回消息,如命令提示符_Java_Command Line - Fatal编程技术网

Java 在Windows中输入并从控制台获取返回消息,如命令提示符

Java 在Windows中输入并从控制台获取返回消息,如命令提示符,java,command-line,Java,Command Line,在Windows操作系统的命令提示符(cmd)中: C:\>execution.exe --login user Enter password: Success 工作流程是输入命令->系统返回消息“输入密码:”->输入密码->系统返回消息“成功”。 如何在我的代码中做到这一点? 这是我的,但不行 Process p = Runtime.getRuntime().exec("execution.exe --login user"); BufferedWriter writer = new

在Windows操作系统的命令提示符(cmd)中:

C:\>execution.exe --login user
Enter password:
Success
工作流程是输入命令->系统返回消息“输入密码:”->输入密码->系统返回消息“成功”。 如何在我的代码中做到这一点? 这是我的,但不行

Process p = Runtime.getRuntime().exec("execution.exe --login user");
BufferedWriter writer = new BufferedWriter(
                    new OutputStreamWriter(p.getOutputStream()));
writer.write("mypassword\n");
writer.flush();
writer.close();
BufferedReader stdInput = new BufferedReader(new 
InputStreamReader(p.getInputStream()));

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

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

您得到了什么错误/输出?没有。我已调试,程序无法通过此“s=stdInput.readLine()”。控制台的所有输出为:“系统返回消息:”