Example: Calling a CL program with java.lang.Runtime.exec()

This example shows how to run CL programs from within a Java™ program. In this example, the Java class CallCLPgm runs a CL program.

The CL program uses the Display JVM Jobs (DSPJVMJOB) CL command to display all of the jobs on the system that contain an active Java Virtual Machine. This example assumes that the CL program has been compiled and exists in a library that is called JAVSAMPLIB. The output from the CL program is in the QSYSPRT spooled file.

See Example: Calling a CL command with java.lang.Runtime.exec() for an example of how to call a CL command from within a Java program.

Note: The JAVSAMPLIB is not created as part of the IBM® Developer Kit licensed program (LP) number 5770-JV1 installation process. You must explicitly create the library.

Source code for CallCLPgm Java class

Note: By using the code examples, you agree to the terms of the Code license and disclaimer information.
import java.io.*;
 
public class CallCLPgm
{
   public static void main(String[] args)
   {
      try
      {
         Process theProcess =
                 Runtime.getRuntime().exec("/QSYS.LIB/JAVSAMPLIB.LIB/DSPJVA.PGM");
      }
      catch(IOException e)
      {
         System.err.println("Error on exec() method");
         e.printStackTrace();
      }
   } 
}

Source code for DSPJVA CL program

PGM
    DSPJVMJOB OUTPUT(*PRINT)
ENDPGM