ibm-information-center/dist/eclipse/plugins/i5OS.ic.rzahh_5.4.0.1/cmdcallex.htm

103 lines
4.8 KiB
HTML

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en-us" xml:lang="en-us">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="security" content="public" />
<meta name="Robots" content="index,follow" />
<meta http-equiv="PICS-Label" content='(PICS-1.1 "http://www.icra.org/ratingsv02.html" l gen true r (cz 1 lz 1 nz 1 oz 1 vz 1) "http://www.rsac.org/ratingsv01.html" l gen true r (n 0 s 0 v 0 l 0) "http://www.classify.org/safesurf/" l gen true r (SS~~000 1))' />
<meta name="DC.Type" content="reference" />
<meta name="DC.Title" content="Example: Using CommandCall" />
<meta name="abstract" content="" />
<meta name="description" content="" />
<meta name="copyright" content="(C) Copyright IBM Corporation 2006" />
<meta name="DC.Rights.Owner" content="(C) Copyright IBM Corporation 2006" />
<meta name="DC.Format" content="XHTML" />
<meta name="DC.Identifier" content="cmdcallex" />
<meta name="DC.Language" content="en-us" />
<!-- All rights reserved. Licensed Materials Property of IBM -->
<!-- US Government Users Restricted Rights -->
<!-- Use, duplication or disclosure restricted by -->
<!-- GSA ADP Schedule Contract with IBM Corp. -->
<link rel="stylesheet" type="text/css" href="./ibmdita.css" />
<link rel="stylesheet" type="text/css" href="./ic.css" />
<title>Example: Using CommandCall</title>
</head>
<body id="cmdcallex"><a name="cmdcallex"><!-- --></a>
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
<h1 class="topictitle1">Example: Using CommandCall</h1>
<div><p></p>
<div class="section"><p>Use the following as an example for your program.</p>
<div class="note"><span class="notetitle">Note:</span> Read
the <a href="codedisclaimer.htm#codedisclaimer">Code example disclaimer</a> for
important legal information.</div>
<pre>//////////////////////////////////////////////////////////////////////////////////
//
// Example using the IBM Toolbox for Java's access class, CommandCall.
//
// This source is an example of IBM Toolbox for Java "Job List".
//
//////////////////////////////////////////////////////////////////////////////////
//
// The access classes of IBM Toolbox for Java are in the
// com.ibm.as400.access.package. Import this package to use the IBM Toolbox for
// Java classes.
//
//////////////////////////////////////////////////////////////////////////////////
import com.ibm.as400.access.*;
public class CmdCall
{
public static void main(String[] args)
{
// Like other Java classes, IBM Toolbox for Java classes
// throw exceptions when something goes wrong. These must
// be caught by programs that use IBM Toolbox for Java.
try <a href="#cmdcallex__one">Note 1 </a>
{
AS400 system = new AS400();
CommandCall cc = new CommandCall(system); <a href="#cmdcallex__two">Note 2 </a>
cc.run("CRTLIB MYLIB"); <a href="#cmdcallex__three">Note 3 </a>
AS400Message[] ml = cc.getMessageList(); <a href="#cmdcallex__four">Note 4 </a>
for (int i=0; i&lt;ml.length; i++)
{
System.out.println(ml[i].getText()); <a href="#cmdcallex__five">Note 5 </a>
}
}
catch (Exception e)
{
e.printStackTrace();
}
System.exit(0);
}
}</pre>
</div>
<div class="section"><ol><li id="cmdcallex__one"><a name="cmdcallex__one"><!-- --></a>IBM<sup>®</sup> Toolbox
for Java™ uses
the "AS400" object to identify the target server. If you construct the AS400
object with no parameters, IBM Toolbox for Java prompts for the system name, userid
and password. The AS400 class also includes a constructor that takes the system
name, userid and password.</li>
<li id="cmdcallex__two"><a name="cmdcallex__two"><!-- --></a>Use the IBM Toolbox for Java CommandCall object to send commands
to the server. When you create the CommandCall object, you pass it an AS400
object so that it knows which server is the target of the command.</li>
<li id="cmdcallex__three"><a name="cmdcallex__three"><!-- --></a>Use the run() method on the command call object to run a command.</li>
<li id="cmdcallex__four"><a name="cmdcallex__four"><!-- --></a>The result of running a command is a list of i5/OS™ messages. IBM Toolbox
for Java represents
these messages as AS400Message objects. When the command is complete, you
get the resulting messages from the CommandCall object.</li>
<li id="cmdcallex__five"><a name="cmdcallex__five"><!-- --></a>Print the message text. Also available are the message ID, message
severity, and other information. This program prints only the message text.</li>
</ol>
</div>
</div>
</body>
</html>