Creating Native Processes from Java: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 13: Line 13:




<tt>ProcessBuilder.start()</tt> is now the preferred way to start a process with a modified environment.
<tt>ProcessBuilder.start()</tt> is the preferred way to start a process with a modified environment.


=Runtime.exec()=
=Runtime.exec()=

Revision as of 02:19, 23 February 2016

External

Internal

Overview

ProcessBuilder.start()

ProcessBuilder.start() is the preferred way to start a process with a modified environment.

Runtime.exec()

Runtime.exec() creates a new O/S process and executes the specified command and arguments in a separate process with the specified environment variables and working directory.

If the environment variable array in null, the subprocess inherits the environment settings of the current Java process. If the working directory is null, the subprocess inherits the current working directory of the current process.

envp - array of strings, each element of which has environment variable settings in the format name=value, or null if the subprocess should inherit the environment of the current process. dir - the working directory of the subprocess, or null if the subprocess should inherit the working directory of the current process. Returns: A new Process object for managing the subprocess Throws: SecurityException - If a security manager exists and its checkExec method doesn't allow creation of the subprocess IOException - If an I/O error occurs NullPointerException - If cmdarray is null, or one of the elements of cmdarray is null, or one of the elements of envp is null IndexOutOfBoundsException - If cmdarray is an empty array (has length 0) Since:

Canonical form:

public Process Runtime.exec(String[] cmdarray, String[] envp, File dir) throws Exception