////////////////////////////////////////////////////////////////////////////////// // // Command call example. This program prompts the user // for the name of the AS/400 and the command to run, then // prints the result of the command. // ////////////////////////////////////////////////////////////////////////////////// // // This source is an example of AS/400 Toolbox for Java "CommandCall" // IBM grants you a nonexclusive license to use this as an example // from which you can generate similar function tailored to // your own specific needs. // // This sample code is provided by IBM for illustrative purposes // only. These examples have not been thoroughly tested under all // conditions. IBM, therefore, cannot guarantee or imply // reliability, serviceability, or function of these programs. // // All programs contained herein are provided to you "AS IS" // without any warranties of any kind. The implied warranties of // merchantablility and fitness for a particular purpose are // expressly disclaimed. // // AS/400 Toolbox for Java // (C) Copyright IBM Corp. 1997 // All rights reserved. // US Government Users Restricted Rights - // Use, duplication, or disclosure restricted // by GSA ADP Schedule Contract with IBM Corp. // ////////////////////////////////////////////////////////////////////////////////// import java.io.*; import java.util.*; import com.ibm.as400.access.*; public class CommandCallExample extends Object { public static void main(String[] parmeters) { // Created a reader to get input from the user BufferedReader inputStream = new BufferedReader(new InputStreamReader(System.in),1); // Declare variables to hold the system name and the command to run String systemString = null; String commandString = null; System.out.println( " " ); // Get the system name and the command to run from the user try { System.out.print("System name: "); systemString = inputStream.readLine(); System.out.print("Command: "); commandString = inputStream.readLine(); } catch (Exception e) {}; System.out.println( " " ); // Create an AS400 object. This is the system we send the command to AS400 as400 = new AS400(systemString); // Create a command call object specifying the AS/400 that will // recieve the command. CommandCall command = new CommandCall( as400 ); try { // Run the command. if (command.run(commandString)) System.out.print( "Command successful" ); else System.out.print( "Command failed" ); // If messages were produced from the command, print them AS400Message[] messagelist = command.getMessageList(); if (messagelist.length > 0) { System.out.println( ", messages from the command:" ); System.out.println( " " ); } for (int i=0; i < messagelist.length; i++) { System.out.print ( messagelist[i].getID() ); System.out.print ( ": " ); System.out.println( messagelist[i].getText() ); } } catch (Exception e) { System.out.println( "Command " + command.getCommand() + " did not run" ); } System.exit(0); } }