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 error stream returned by process execution is not in readable format.
- I am getting error stream result even if the termination of cobol code returns 0.
- 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.