简体   繁体   中英

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. The java code is in IFS file structure and the cobol object is parked in a library. 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.
  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 )

The cobol code works when invoke independently. I have tried encoding UTF8,UTF16, Cp943 and default. When I use UTF8,UTF16 I get MalformedInputException, else a garbage value.

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

I used "Cp037" for USA instead of UTF8 and other format.

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. 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.

When I want to call a program on IBM i, I use the JTOpen IBM Toolbox for Java . The Javadoc can be hard to find if you're not familiar with the IBM Infocenter .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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