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.
The actual processing that occurs depends on the following items:
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.
Type of command | Value of os400.runtime.exec system property | |
---|---|---|
EXEC (default value) | QSHELL | |
java command | Starts a second job that runs the JVM. The JVM starts a third job that runs the Java application. | Starts a second job that runs Qshell, the shell interpreter. Qshell starts a third job to run the Java application, program, or command. |
program | Starts a second job that runs an executable program (i5/OS™ program or i5/OS PASE program). | |
CL command | Starts a second job that runs an i5/OS program. The i5/OS program runs the CL command in the second job. |
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.
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.
Using a value of EXEC instead of QSHELL has the following advantages:
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.
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.
Figure 1. Using a value of QSHELL
for the os400.runtime.exec system property
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.
For information about setting os400.runtime.exec, see List of Java system properties.