【问题标题】:how to bind a windows console application with java application?如何将 Windows 控制台应用程序与 java 应用程序绑定?
【发布时间】:2011-01-07 19:12:04
【问题描述】:

我有一个用 C++ 编写并在 Windows 控制台上运行的可执行程序 (.exe) 我有一个 java swing 应用程序,所以我希望我的 java 应用程序能够交互 使用控制台应用程序(发送输入并获取输出)。 但是该怎么做呢?

【问题讨论】:

  • 你有能力修改可执行文件吗?

标签: java console-application


【解决方案1】:

你可以这样做

// 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");

【讨论】:

    【解决方案2】:

    您可以从 Java 程序中启动 C++ 程序,该程序允许您写入其标准输入并读取其标准输出。检查Runtime 类。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-11-04
      • 2011-04-22
      • 1970-01-01
      • 1970-01-01
      • 2014-01-24
      • 1970-01-01
      • 1970-01-01
      • 2011-09-27
      相关资源
      最近更新 更多