Runtime.Exec Method

Definition

Overloads

Exec(String)

Executes the specified string command in a separate process.

Exec(String[])

Executes the specified command and arguments in a separate process.

Exec(String, String[])

Executes the specified string command in a separate process with the specified environment.

Exec(String[], String[])

Executes the specified command and arguments in a separate process with the specified environment.

Exec(String, String[], File)

Executes the specified string command in a separate process with the specified environment and working directory.

Exec(String[], String[], File)

Executes the specified command and arguments in a separate process with the specified environment and working directory.

Exec(String)

Executes the specified string command in a separate process.

[Android.Runtime.Register("exec", "(Ljava/lang/String;)Ljava/lang/Process;", "GetExec_Ljava_lang_String_Handler")]
public virtual Java.Lang.Process? Exec (string? command);
[<Android.Runtime.Register("exec", "(Ljava/lang/String;)Ljava/lang/Process;", "GetExec_Ljava_lang_String_Handler")>]
abstract member Exec : string -> Java.Lang.Process
override this.Exec : string -> Java.Lang.Process

Parameters

command
String

a specified system command.

Returns

A new Process object for managing the subprocess

Attributes

Exceptions

if the requested program can not be executed.

Remarks

Executes the specified string command in a separate process.

This is a convenience method. An invocation of the form exec(command) behaves in exactly the same way as the invocation #exec(String, String[], File) exec(command, null, null).

Java documentation for java.lang.Runtime.exec(java.lang.String).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

Exec(String[])

Executes the specified command and arguments in a separate process.

[Android.Runtime.Register("exec", "([Ljava/lang/String;)Ljava/lang/Process;", "GetExec_arrayLjava_lang_String_Handler")]
public virtual Java.Lang.Process? Exec (string[]? cmdarray);
[<Android.Runtime.Register("exec", "([Ljava/lang/String;)Ljava/lang/Process;", "GetExec_arrayLjava_lang_String_Handler")>]
abstract member Exec : string[] -> Java.Lang.Process
override this.Exec : string[] -> Java.Lang.Process

Parameters

cmdarray
String[]

array containing the command to call and its arguments.

Returns

A new Process object for managing the subprocess

Attributes

Exceptions

if the requested program can not be executed.

Remarks

Executes the specified command and arguments in a separate process.

This is a convenience method. An invocation of the form exec(cmdarray) behaves in exactly the same way as the invocation #exec(String[], String[], File) exec(cmdarray, null, null).

Java documentation for java.lang.Runtime.exec(java.lang.String[]).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

Exec(String, String[])

Executes the specified string command in a separate process with the specified environment.

[Android.Runtime.Register("exec", "(Ljava/lang/String;[Ljava/lang/String;)Ljava/lang/Process;", "GetExec_Ljava_lang_String_arrayLjava_lang_String_Handler")]
public virtual Java.Lang.Process? Exec (string? command, string[]? envp);
[<Android.Runtime.Register("exec", "(Ljava/lang/String;[Ljava/lang/String;)Ljava/lang/Process;", "GetExec_Ljava_lang_String_arrayLjava_lang_String_Handler")>]
abstract member Exec : string * string[] -> Java.Lang.Process
override this.Exec : string * string[] -> Java.Lang.Process

Parameters

command
String

a specified system command.

envp
String[]

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.

Returns

A new Process object for managing the subprocess

Attributes

Exceptions

if the requested program can not be executed.

Remarks

Executes the specified string command in a separate process with the specified environment.

This is a convenience method. An invocation of the form exec(command, envp) behaves in exactly the same way as the invocation #exec(String, String[], File) exec(command, envp, null).

Java documentation for java.lang.Runtime.exec(java.lang.String, java.lang.String[]).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

Exec(String[], String[])

Executes the specified command and arguments in a separate process with the specified environment.

[Android.Runtime.Register("exec", "([Ljava/lang/String;[Ljava/lang/String;)Ljava/lang/Process;", "GetExec_arrayLjava_lang_String_arrayLjava_lang_String_Handler")]
public virtual Java.Lang.Process? Exec (string[]? cmdarray, string[]? envp);
[<Android.Runtime.Register("exec", "([Ljava/lang/String;[Ljava/lang/String;)Ljava/lang/Process;", "GetExec_arrayLjava_lang_String_arrayLjava_lang_String_Handler")>]
abstract member Exec : string[] * string[] -> Java.Lang.Process
override this.Exec : string[] * string[] -> Java.Lang.Process

Parameters

cmdarray
String[]

array containing the command to call and its arguments.

envp
String[]

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.

Returns

A new Process object for managing the subprocess

Attributes

Exceptions

if the requested program can not be executed.

Remarks

Executes the specified command and arguments in a separate process with the specified environment.

This is a convenience method. An invocation of the form exec(cmdarray, envp) behaves in exactly the same way as the invocation #exec(String[], String[], File) exec(cmdarray, envp, null).

Java documentation for java.lang.Runtime.exec(java.lang.String[], java.lang.String[]).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

Exec(String, String[], File)

Executes the specified string command in a separate process with the specified environment and working directory.

[Android.Runtime.Register("exec", "(Ljava/lang/String;[Ljava/lang/String;Ljava/io/File;)Ljava/lang/Process;", "GetExec_Ljava_lang_String_arrayLjava_lang_String_Ljava_io_File_Handler")]
public virtual Java.Lang.Process? Exec (string? command, string[]? envp, Java.IO.File? dir);
[<Android.Runtime.Register("exec", "(Ljava/lang/String;[Ljava/lang/String;Ljava/io/File;)Ljava/lang/Process;", "GetExec_Ljava_lang_String_arrayLjava_lang_String_Ljava_io_File_Handler")>]
abstract member Exec : string * string[] * Java.IO.File -> Java.Lang.Process
override this.Exec : string * string[] * Java.IO.File -> Java.Lang.Process

Parameters

command
String

a specified system command.

envp
String[]

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
File

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

Attributes

Exceptions

if the requested program can not be executed.

Remarks

Executes the specified string command in a separate process with the specified environment and working directory.

This is a convenience method. An invocation of the form exec(command, envp, dir) behaves in exactly the same way as the invocation #exec(String[], String[], File) exec(cmdarray, envp, dir), where cmdarray is an array of all the tokens in command.

More precisely, the command string is broken into tokens using a StringTokenizer created by the call new {@link StringTokenizer(command)} with no further modification of the character categories. The tokens produced by the tokenizer are then placed in the new string array cmdarray, in the same order.

Added in 1.3.

Java documentation for java.lang.Runtime.exec(java.lang.String, java.lang.String[], java.io.File).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

Exec(String[], String[], File)

Executes the specified command and arguments in a separate process with the specified environment and working directory.

[Android.Runtime.Register("exec", "([Ljava/lang/String;[Ljava/lang/String;Ljava/io/File;)Ljava/lang/Process;", "GetExec_arrayLjava_lang_String_arrayLjava_lang_String_Ljava_io_File_Handler")]
public virtual Java.Lang.Process? Exec (string[]? cmdarray, string[]? envp, Java.IO.File? dir);
[<Android.Runtime.Register("exec", "([Ljava/lang/String;[Ljava/lang/String;Ljava/io/File;)Ljava/lang/Process;", "GetExec_arrayLjava_lang_String_arrayLjava_lang_String_Ljava_io_File_Handler")>]
abstract member Exec : string[] * string[] * Java.IO.File -> Java.Lang.Process
override this.Exec : string[] * string[] * Java.IO.File -> Java.Lang.Process

Parameters

cmdarray
String[]

array containing the command to call and its arguments.

envp
String[]

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
File

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

Attributes

Exceptions

if the requested program can not be executed.

Remarks

Executes the specified command and arguments in a separate process with the specified environment and working directory.

Given an array of strings cmdarray, representing the tokens of a command line, and an array of strings envp, representing "environment" variable settings, this method creates a new process in which to execute the specified command.

This method checks that cmdarray is a valid operating system command. Which commands are valid is system-dependent, but at the very least the command must be a non-empty list of non-null strings.

If envp is null, the subprocess inherits the environment settings of the current process.

A minimal set of system dependent environment variables may be required to start a process on some operating systems. As a result, the subprocess may inherit additional environment variable settings beyond those in the specified environment.

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

The working directory of the new subprocess is specified by dir. If dir is null, the subprocess inherits the current working directory of the current process.

If a security manager exists, its SecurityManager#checkExec checkExec method is invoked with the first component of the array cmdarray as its argument. This may result in a SecurityException being thrown.

Starting an operating system process is highly system-dependent. Among the many things that can go wrong are: <ul> <li>The operating system program file was not found. <li>Access to the program file was denied. <li>The working directory does not exist. </ul>

In such cases an exception will be thrown. The exact nature of the exception is system-dependent, but it will always be a subclass of IOException.

If the operating system does not support the creation of processes, an UnsupportedOperationException will be thrown.

Added in 1.3.

Java documentation for java.lang.Runtime.exec(java.lang.String[], java.lang.String[], java.io.File).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to