我有一个用 C++ 编写并在 Windows 控制台上运行的可执行程序 (.exe)
我有一个 java swing 应用程序,所以我希望我的 java 应用程序能够交互
使用控制台应用程序(发送输入并获取输出)。
但怎么做呢?
最佳答案
你可以这样做
// Create the proccess in JAVA
Process proc = Runtime.getRuntime().exec("Name of application");
// Receive outputs from another program inside Java by a stream
InputStream ips = proc.getInputStream();
// Using the stream to get the messages from another program
String output = "";
int c = 0;
while ((c = ips.read()) != -1){
output+= (char)c;
}
//Inputs messages into another program
OutputStream ops = proc.getOutputStream();
ops.write("an byte array");
关于java - 如何将 Windows 控制台应用程序与 java 应用程序绑定(bind)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2110415/