143 lines
9.8 KiB
HTML
143 lines
9.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="concept" />
|
|
<meta name="DC.Title" content="Use java.lang.Runtime.exec()" />
|
|
<meta name="abstract" content="Use the java.lang.Runtime.exec method to call programs or commands from within your Java program. Using java.lang.Runtime.exec() method creates one or more additional thread-enabled jobs. The additional jobs process the command string that you pass on the method." />
|
|
<meta name="description" content="Use the java.lang.Runtime.exec method to call programs or commands from within your Java program. Using java.lang.Runtime.exec() method creates one or more additional thread-enabled jobs. The additional jobs process the command string that you pass on the method." />
|
|
<meta name="DC.Relation" scheme="URI" content="othlang.htm" />
|
|
<meta name="DC.Relation" scheme="URI" content="jni.htm" />
|
|
<meta name="DC.Relation" scheme="URI" content="rzahapaseexmplsmain.htm" />
|
|
<meta name="DC.Relation" scheme="URI" content="rzahateraspacemain.htm" />
|
|
<meta name="DC.Relation" scheme="URI" content="ilejava.htm" />
|
|
<meta name="DC.Relation" scheme="URI" content="interpro.htm" />
|
|
<meta name="DC.Relation" scheme="URI" content="jvlngex1.htm" />
|
|
<meta name="DC.Relation" scheme="URI" content="callclex.htm" />
|
|
<meta name="DC.Relation" scheme="URI" content="clcommex.htm" />
|
|
<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="javalang" />
|
|
<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>Use java.lang.Runtime.exec()</title>
|
|
</head>
|
|
<body id="javalang"><a name="javalang"><!-- --></a>
|
|
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
|
|
<h1 class="topictitle1">Use java.lang.Runtime.exec()</h1>
|
|
<div><p>Use the java.lang.Runtime.exec method to call programs or commands
|
|
from within your Java™ program. Using java.lang.Runtime.exec() method
|
|
creates one or more additional thread-enabled jobs. The additional jobs process
|
|
the command string that you pass on the method.</p>
|
|
<div class="note"><span class="notetitle">Note:</span> The java.lang.Runtime.exec method runs programs in a separate job, which
|
|
is different than the C system() function. The C system function runs programs
|
|
in the same job.</div>
|
|
<p>The actual processing that occurs depends on the following items:</p>
|
|
<ul><li>The kind of command that you pass in on java.lang.Runtime.exec()</li>
|
|
<li>The value of the os400.runtime.exec system property</li>
|
|
</ul>
|
|
<div class="section"><h4 class="sectiontitle">Processing different types of commands </h4><p>The following
|
|
table indicates how java.lang.Runtime.exec() processes different kinds of
|
|
commands and shows the effects of the os400.runtime.exec system property.</p>
|
|
|
|
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" width="100%" frame="border" border="1" rules="all"><thead align="left"><tr><th rowspan="2" valign="top" id="d0e36"> Type of command</th>
|
|
<th colspan="2" valign="top" id="d0e38">Value of os400.runtime.exec system property</th>
|
|
</tr>
|
|
<tr><th valign="top" id="d0e41">EXEC (default value)</th>
|
|
<th valign="top" id="d0e43">QSHELL</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody><tr><td valign="top" headers="d0e36 "><strong>java command</strong></td>
|
|
<td valign="top" headers="d0e38 d0e41 ">Starts a second job that runs the JVM. The JVM starts a third job that
|
|
runs the Java application.</td>
|
|
<td rowspan="3" valign="top" headers="d0e38 d0e43 ">Starts a second job that runs Qshell, the shell interpreter.
|
|
Qshell starts a third job to run the Java application, program, or command.</td>
|
|
</tr>
|
|
<tr><td valign="top" headers="d0e36 "><strong>program</strong></td>
|
|
<td valign="top" headers="d0e38 d0e41 ">Starts a second job that runs an executable program (<span class="keyword">i5/OS™</span> program
|
|
or <span class="keyword">i5/OS</span> PASE program).</td>
|
|
</tr>
|
|
<tr><td valign="top" headers="d0e36 "><strong>CL command</strong></td>
|
|
<td valign="top" headers="d0e38 d0e41 ">Starts a second job that runs an <span class="keyword">i5/OS</span> program.
|
|
The <span class="keyword">i5/OS</span> program runs
|
|
the CL command in the second job.</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
<div class="note"><span class="notetitle">Note:</span> When calling a CL command or CL program, make sure that the
|
|
job CCSID contains the characters that you pass as parameters to the called
|
|
command.</div>
|
|
<p>The processing in the second or third job runs concurrently
|
|
with any Java virtual machine (JVM) in the original job. Any
|
|
exit or shutdown processing in those jobs does not affect the original JVM.</p>
|
|
</div>
|
|
<div class="section"><h4 class="sectiontitle">os400.runtime.exec system property</h4><p>You can set the
|
|
value of the os400.runtime.exec system property to EXEC (the default value)
|
|
or QSHELL. The value of os400.runtime.exec determines whether java.lang.Runtime.exec()
|
|
uses the EXEC interface or Qshell.</p>
|
|
<p>Using a value of EXEC instead of
|
|
QSHELL has the following advantages:</p>
|
|
<ul><li>Your Java program that calls java.lang.Runtime.exec() is
|
|
more portable</li>
|
|
<li>Using java.lang.Runtime.exec() to call a CL command uses fewer system
|
|
resources </li>
|
|
</ul>
|
|
<p>You should use java.lang.Runtime.exec() to run Qshell only when backward
|
|
compatibility requires it. Using java.lang.Runtime.exec() to run Qshell requires
|
|
that you set os400.runtime.exec to QSHELL.</p>
|
|
<p>The following illustration
|
|
shows how using a value of QSHELL launches a third job, which consumes additional
|
|
system resources. Remember that using a value of QSHELL decreases the portability
|
|
of your Java program.</p>
|
|
<p><strong>Figure 1. Using a value of QSHELL
|
|
for the os400.runtime.exec system property</strong><br /><img src="rzaha501.gif" alt="This graphic shows that using a value of QSHELL for the os400.runtime.exec
system property causes a process to launch a second and then a third job." /><br /></p>
|
|
<p>Also, when you use a value of QSHELL, passing a CL command
|
|
to java.lang.Runtime.exec() requires specific syntax. For more information,
|
|
see the following example for calling a CL command.</p>
|
|
<p>For information
|
|
about setting os400.runtime.exec, see <a href="sysprop2.htm">List of Java system
|
|
properties</a>.</p>
|
|
</div>
|
|
</div>
|
|
<div>
|
|
<ul class="ullinks">
|
|
<li class="ulchildlink"><strong><a href="jvlngex1.htm">Example: Call another Java program with java.lang.Runtime.exec()</a></strong><br />
|
|
This example shows how to call another Java program with java.lang.Runtime.exec().
|
|
This class calls the Hello program that is shipped as part of the IBM<sup>®</sup> Developer
|
|
Kit for Java. When the Hello class writes to System.out, this
|
|
program gets a handle to the stream and can read from it.</li>
|
|
<li class="ulchildlink"><strong><a href="callclex.htm">Example: Call a CL program with java.lang.Runtime.exec()</a></strong><br />
|
|
This example shows how to run CL programs from within a Java program.
|
|
In this example, the Java class CallCLPgm runs a CL program.</li>
|
|
<li class="ulchildlink"><strong><a href="clcommex.htm">Example: Call a CL command with java.lang.Runtime.exec()</a></strong><br />
|
|
This example shows how to run a control language (CL) command from
|
|
within a Java program.</li>
|
|
</ul>
|
|
|
|
<div class="familylinks">
|
|
<div class="parentlink"><strong>Parent topic:</strong> <a href="othlang.htm" title="With Java, you have multiple ways to call code that was written in languages other than Java.">Java with other programming languages</a></div>
|
|
</div>
|
|
<div class="relconcepts"><strong>Related concepts</strong><br />
|
|
<div><a href="rzahapaseexmplsmain.htm" title="The iSeries Java virtual machine (JVM) supports the use of native methods running in the i5/OS PASE environment. Prior to V5R2, the native iSeries JVM used only ILE native methods.">IBM i5/OS PASE native methods for Java</a></div>
|
|
<div><a href="rzahateraspacemain.htm" title="The iSeries Java virtual machine (JVM) now supports the use of teraspace storage model native methods. The teraspace storage model provides a large process-local address environment for ILE programs. Using teraspace allows you to port native method code from other operating systems to i5/OS with little or no source code changes.">Teraspace storage model native methods for Java</a></div>
|
|
<div><a href="ilejava.htm" title="The Java environment on an iSeries server is separate from the integrated language environment (ILE). Java is not an ILE language, and it cannot bind to ILE object modules to create programs or service programs on an iSeries server.">Comparison of Integrated Language Environment and Java</a></div>
|
|
<div><a href="interpro.htm" title="When communicating with programs that are running in another process, there are a number of options.">Interprocess communications</a></div>
|
|
</div>
|
|
<div class="reltasks"><strong>Related tasks</strong><br />
|
|
<div><a href="jni.htm" title="You should only use native methods in cases where pure Java cannot meet your programming needs.">Use the Java Native Interface for native methods</a></div>
|
|
</div>
|
|
</div>
|
|
</body>
|
|
</html> |