The CommandCall class allows a Java program to call a non-interactive AS/400 command. Results of the command are available in a list of AS400 Message 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 AS/400 messages resulting from the command.
Using the CommandCall class causes the AS400 object to connect to the AS/400.
The following example shows how to use the CommandCall class run a command on an AS/400 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 AS/400 sys.disconnectService(AS400.COMMAND);
Using the CommandCall class causes the AS400 object to connect to the AS/400. See managing connections for information on managing connections.
Example
Run a command that is specified by the user.