CommandCall class

The CommandCall class allows a Java™ program to call a non-interactive IBM® i command.

Results of the command are available in a list of AS400Message objects.

Input to CommandCall is as follows:

  • The command string to run
  • The AS400 object that represents the system that will run the command

The command string can be set on the constructor, through the CommandCall setCommand() method, or on the run() method. After the command is run, the Java program can use the getMessageList() method to retrieve any IBM i messages resulting from the command.

Using the CommandCall class causes the AS400 object to connect to the system. See managing connections for information about managing connections.

When the Java program and the IBM i command are on the same server, the default IBM Toolbox for Java behavior is to look up the thread safety for the command on the system. If threadsafe, the command is run on-thread. You can suppress the run-time lookup by explicitly specifying thread-safety for the command by using the setThreadSafe() method.

Examples

The following examples show ways you can use the CommandCall class to run different kinds of commands.
Note: Read the Code example disclaimer for important legal information.

Example: Running a command

The following example shows how to use the CommandCall class to run a command on the system:

     // Create an AS400 object.
     AS400 sys = new AS400("mySystem.myCompany.com");

     // Create a command call object. This
     // program sets the command to run later.
     // It could set it here on the constructor.
     CommandCall cmd = new CommandCall(sys);

     // Run the CRTLIB command
     cmd.run("CRTLIB MYLIB");

     // Get the message list which
     // contains the result of the command.
     AS400Message[] messageList = cmd.getMessageList();

     // ... process the message list.

     // Disconnect since I am done sending
     // commands to the server
     sys.disconnectService(AS400.COMMAND);

Example: Running a user-specified command

Example: Using CommandCall shows how to run a command that is specified by the user.