在java中执行外部程序并传递命令 [英] Executing external program in java and passing commands

查看:291
本文介绍了在java中执行外部程序并传递命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个国际象棋引擎Rybka.exe,我必须在java
执行这里是一个例子你如何运行Rybka:
一旦你点击它,控制台打开并等待输入。
那么你输入uci,然后按enter键等待它加载(大约1秒),然后你必须输入更多的行作为选项和东西。
问题是,我不知道如何将这些命令从java传递给Rybka。事实是,这些命令需要一次输入一个,因为你必须等待一些执行。
这是我怎么打开它。
代码:

  Process p1 = Runtime.getRuntime()。exec(Rybka.exe); 

这样工作,因为你可以看到Rybka.exe在任务管理器中是活动的,

如何使用java应用程序绑定Windows控制台应用程序?



链接由Google搜索查询提供:



https://www.google.pl/search?q=java+binding+console+to+an+app&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-美国:官方&客户= firefox-a



b)简而言之:

  InputStream is = p1.getInputStream(); 
OutputStream os = p1.getOutputStream();

(由明显的 http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Process.html


I have this chess engine Rybka.exe, that i have to execute in java Here is an example how you run Rybka: Once you clicked on it, console opens and waits for input. So then you enter "uci" and you press enter and you wait for it to load (approx. 1 sec) and then you have to enter a few more lines as options and stuff. The problem is that I don't know how to pass those commands from java to Rybka. The fact is that those commands need to be entered one at a time, because you have to wait for some to execute. This is how I tried to open it. Code:

Process p1 = Runtime.getRuntime().exec("Rybka.exe");

This works, because you can see that Rybka.exe is active in task manager, but I don't know how to pass commands to it.

解决方案

a) how to bind a windows console application with java application?

link provided by the courtesy of Google search query:

https://www.google.pl/search?q=java+binding+console+to+an+app&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-US:official&client=firefox-a

b) in short:

 InputStream is = p1.getInputStream();
 OutputStream os = p1.getOutputStream();

(supplied by the obvious http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Process.html)

这篇关于在java中执行外部程序并传递命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆