如何将Windows控制台应用程序与Java应用程序绑定?

发布于 2024-08-19 02:27:29 字数 118 浏览 2 评论 0原文

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

i have an executable program (.exe) writen in c++ and run on windows console
and i have a java swing applecation , so i want my java application to interact
with the console app (send input and get output) .
but how to do that ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦一生花开无言 2024-08-26 02:27:29

你可以这样做

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

You can do it this way

// 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");
且行且努力 2024-08-26 02:27:29

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

You can launch the C++ program from within the Java program which allows you to write to its standard input, and read its standard output. Check the Runtime class.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文