java - 如何将 Windows 控制台应用程序与 java 应用程序绑定(bind)?

标签 java console-application

我有一个用 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/

相关文章:

java - 如何将用户从 Gallery 重定向到我在 Android 中的应用程序?

java - Hibernate 抛出错误并检查列重复 : Adding Hibernate classes at runtime with metadata

java - Eclipse插件: get extended class name using ASTParser

c# - 没有背景颜色的控制台文本填充

c# - 如何在Azure Function C#中获取文件夹路径

java - 从失败中恢复的数据库错误 Qualtz

c# - 如何在类里面再次调用 "static void Main(string[] args) "

c++ - 计算 vector 中偶数长度的单词

c# - PostAsync 返回异常

java - 无效的 if 语句