Reputation: 437
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:
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.
Upvotes: 0
Views: 474
Reputation: 7633
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.
Upvotes: 1
Reputation: 437
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"));
Upvotes: 2