我正在尝试通过 java 调用一个简单的 Hello World Cobol 程序。 java代码位于IFS文件结构中,cobol对象存放在库中。 我面临多个问题:
- 流程执行返回的错误流格式不可读。
- 即使 cobol 代码终止返回 0,我也会收到错误流结果。
- 我在进程的输入流中看不到 cobol 输出结果。(如果我理解错误流,也许我可以解决这个问题)
cobol 代码在独立调用时有效。 我尝试过编码 UTF8、UTF16、Cp943 和默认。 当我使用 UTF8、UTF16 时,我得到 MalformedInputException,否则是一个垃圾值。
Java代码:(@AS 400本身编译-java 1.5)
import java.io.*; public class CallCLPgm { public static void main(String[] args) { try { Process theProcess = Runtime.getRuntime().exec("system CALL PROG6"); //error stream BufferedReader inStream1 = new BufferedReader(new InputStreamReader (theProcess.getErrorStream(),"UTF8")); System.out.println(inStream1.readLine()); inStream1.close(); //input stream BufferedReader inStream = new BufferedReader(new InputStreamReader (theProcess.getInputStream())); System.out.println(inStream.readLine()); inStream.close(); System.out.println("termination : "+theProcess.waitFor());
//Cobol code
PROCEDURE DIVISION.
PROGRAM-BEGIN.
DISPLAY "Hello World".
STOP RUN.
最佳答案
我应该关注IBM编码格式 http://publib.boulder.ibm.com/html/as400/v4r5/ic2924/index.htm?info/java/rzaha/fileenc.htm
对于美国,我使用“Cp037”而不是 UTF8 和其他格式。
BufferedReader inStream1 = new BufferedReader(new InputStreamReader (theProcess.getErrorStream(),"Cp037"));
关于java - 在 AS400 上通过 Java 传输运行时进程执行 (cobol obj) 的结果时出现 MalformedInputException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11692715/