简体   繁体   English

MalformedInputException而在AS400上通过Java流化运行时进程执行(cobol obj)的结果时

[英]MalformedInputException while streaming results from Runtime process execution(cobol obj) via Java on AS400

I am trying to invoke a simple Hello World Cobol program through java. 我正在尝试通过java调用一个简单的Hello World Cobol程序。 The java code is in IFS file structure and the cobol object is parked in a library. Java代码采用IFS文件结构,并且cobol对象停放在库中。 I am facing multiple problems: 我面临多个问题:

  1. The error stream returned by process execution is not in readable format. 流程执行返回的错误流不是可读格式。
  2. I am getting error stream result even if the termination of cobol code returns 0. 即使cobol代码的终止返回0,我也得到错误流结果。
  3. I cannot see the cobol output result in the inputstream of the process.(May be I can solve this if i understand the error stream ) 我在进程的输入流中看不到cobol输出结果。(如果我理解错误流,可以解决这个问题)

The cobol code works when invoke independently. 当独立调用时,cobol代码有效。 I have tried encoding UTF8,UTF16, Cp943 and default. 我已经尝试编码UTF8,UTF16,Cp943和默认值。 When I use UTF8,UTF16 I get MalformedInputException, else a garbage value. 当我使用UTF8,UTF16时,会收到MalformedInputException,否则为垃圾值。

Java code:(compiled @ AS 400 itself -java 1.5) 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.  

I should have focused on IBM encoding format http://publib.boulder.ibm.com/html/as400/v4r5/ic2924/index.htm?info/java/rzaha/fileenc.htm 我应该专注于IBM编码格式http://publib.boulder.ibm.com/html/as400/v4r5/ic2924/index.htm?info/java/rzaha/fileenc.htm

I used "Cp037" for USA instead of UTF8 and other format. 我在美国使用的是“ Cp037”,而不是UTF8和其他格式。

BufferedReader inStream1 = new BufferedReader(new InputStreamReader (theProcess.getErrorStream(),"Cp037")); BufferedReader inStream1 = new BufferedReader(new InputStreamReader(theProcess.getErrorStream(),“ Cp037”));

I am not a Cobol programmer but I think that the Cobol verb DISPLAY does not write to stdout. 我不是Cobol程序员,但我认为Cobol动词DISPLAY不会写入stdout。 Check with the Cobol manual, but my guess is that you will need to actually open stdout in your Cobol program and write to it rather than use DISPLAY. 请查阅Cobol手册,但我想您将需要在Cobol程序中实际打开stdout并对其进行写入,而不是使用DISPLAY。

When I want to call a program on IBM i, I use the JTOpen IBM Toolbox for Java . 当我想在IBM i上调用程序时,请使用JTOpen IBM Toolbox for Java The Javadoc can be hard to find if you're not familiar with the IBM Infocenter . 如果您不熟悉IBM Infocenter,可能很难找到Javadoc

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM