[英]java runtime process exec
i need to do a mainframe wrapper, the mainframe runs Music SP and it can be access by TN3270 terminal. 我需要做一个主机包装,该主机运行Music SP,并且可以通过TN3270终端进行访问。
i use the terminal emulator x3270 and i need to connect with it in java. 我使用终端仿真器x3270,并且需要在Java中与其连接。 I tried with java run time:
我尝试使用Java运行时:
public void init() {
Process p = null;
byte[] buffer = new byte[2048];
Scanner s = new Scanner(System.in);
System.out.println("> Starting server...");
try {
// Execution of mainframe
p = Runtime.getRuntime().exec(
"C:\\Program Files\\wc3270\\wc3270.exe", null);
// Capture I/O
in = new BufferedReader(
new InputStreamReader(p.getInputStream()));
out = new BufferedWriter(
new OutputStreamWriter(p.getOutputStream()));
err = new BufferedReader(
new InputStreamReader(p.getInputStream()));
System.out.println("> OK!");
// Connect/login/enter/tareas.c
System.out.println("> Connecting to Music SP...");
execute("connect XXX.XXX.XXX.XXX:XXX");
enter();
//p.waitFor();
System.out.println("> OK!");
enter();
//p.waitFor();
System.out.println("> Login...");
execute("String(login)");
enter();
execute("String(pass)");
enter();
//p.waitFor();
enter();
System.out.println("> OK!");
System.out.println("> Start tareas.c...");
execute("String(tareas.c)");
enter();
//p.waitFor();
System.out.println("> OK!");
} catch (Exception e) {
e.printStackTrace();
p.destroy();
}
}
public void execute(String query) throws IOException {
if (query != null) {
out.write(query);
out.flush();
}
if (!checkOK()) {
System.out.println(">>> FAIL QUERY");
}
}
public void enter() throws IOException {
out.write("enter");
out.flush();
if (!checkOK()) {
System.out.println(">>> FAIL ENTER");
}
}
public boolean checkOK() {
try {
in.readLine();
return in.readLine().contains("ok");
} catch (Exception e) {
return false;
}
}
But when i execute i get: 但是当我执行我得到:
> Starting server...
OK!
Connecting to Music SP...
FAIL QUERY
FAIL ENTER
OK!
FAIL ENTER
Login...
FAIL QUERY
java.io.IOException: Stream Closed
at java.io.FileOutputStream.writeBytes(Native Method)
at java.io.FileOutputStream.write(Unknown Source)
at java.io.BufferedOutputStream.flushBuffer(Unknown Source)
at java.io.BufferedOutputStream.flush(Unknown Source)
at sun.nio.cs.StreamEncoder.implFlush(Unknown Source)
at sun.nio.cs.StreamEncoder.flush(Unknown Source)
at java.io.OutputStreamWriter.flush(Unknown Source)
at java.io.BufferedWriter.flush(Unknown Source)
at Connection.enter(Connection.java:86)
at Connection.init(Connection.java:57)
at Connection.<init>(Connection.java:20)
at Connection.main(Connection.java:102)
Where and what is the problem? 问题出在哪里?
Other question, when i do a query, how i can wait to do other query? 另一个问题,当我进行查询时,如何等待其他查询? i need to wait between querys
我需要在两次查询之间等待
thanks!! 谢谢!!
IOException can be the cause of these: IOException可能是这些原因:
In your case, as stated above, stream was closed. 如上所述,在您的情况下,流已关闭。
InputStreamReader(InputStream in, String charsetName) InputStreamReader(InputStream in,字符串charsetName)
instead of using default charset, try specifying it 而不是使用默认字符集,请尝试指定它
also see Screen scraping with Java and X3270 另请参阅使用Java和X3270进行屏幕抓取
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.