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

This example shows how to run a control language (CL) command from within a Java™ program.

In this example, the Java class runs a CL command. The CL command uses the Display JVM Jobs (DSPJVMJOB) CL command to display all of the jobs on the system that contain an active Java Virtual Machine. The output from the CL command is in the QSYSPRT spooled file.

CL commands that you pass into the Runtime.getRuntime().exec() function use the following format:

     Runtime.getRuntime().exec("system CLCOMMAND");

where CLCOMMAND is the CL command you want to run.

Source code for Java class for calling a CL command

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