Command call

The CommandCall class allows a Java program to call a non-interactive iSeries command. Results of the command are available in a list of AS400Message objects.

Input to CommandCall is as follows:

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

Using the CommandCall class causes the AS400 object to connect to the iSeries.

The following example shows how to use the CommandCall class run a command on an iSeries 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);

Using the CommandCall class causes the AS400 object to connect to the iSeries. See managing connections for information on managing connections.

Begin changeWhen the Java program and the iSeries server command are on the same server, the default Toolbox for Java behavior is to look up the thread safety for the command on the system.End change 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 using the setThreadSafe() method.

Example

Run a command that is specified by the user.