Creating Native Processes from Java

From NovaOrdis Knowledge Base
Jump to navigation Jump to search

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 (each element of the String[] has a "name=value" format) 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.

The call returns a new Process object for managing the subprocess.

Canonical form:

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