Skip to content

Most visited

Recently visited

navigation

ProcessBuilder.Redirect

public static abstract class ProcessBuilder.Redirect
extends Object

java.lang.Object
   ↳ java.lang.ProcessBuilder.Redirect


Represents a source of subprocess input or a destination of subprocess output. Each Redirect instance is one of the following:

Each of the above categories has an associated unique Type.

Summary

Nested classes

enum ProcessBuilder.Redirect.Type

The type of a ProcessBuilder.Redirect

Fields

public static final ProcessBuilder.Redirect INHERIT

Indicates that subprocess I/O source or destination will be the same as those of the current process.

public static final ProcessBuilder.Redirect PIPE

Indicates that subprocess I/O will be connected to the current Java process over a pipe.

Public methods

static ProcessBuilder.Redirect appendTo(File file)

Returns a redirect to append to the specified file.

boolean equals(Object obj)

Compares the specified object with this Redirect for equality.

File file()

Returns the File source or destination associated with this redirect, or null if there is no such file.

static ProcessBuilder.Redirect from(File file)

Returns a redirect to read from the specified file.

int hashCode()

Returns a hash code value for this Redirect.

static ProcessBuilder.Redirect to(File file)

Returns a redirect to write to the specified file.

abstract ProcessBuilder.Redirect.Type type()

Returns the type of this Redirect.

Inherited methods

From class java.lang.Object

Fields

INHERIT

added in API level 26
ProcessBuilder.Redirect INHERIT

Indicates that subprocess I/O source or destination will be the same as those of the current process. This is the normal behavior of most operating system command interpreters (shells).

It will always be true that

 Redirect.INHERIT.file() == null &&
 Redirect.INHERIT.type() == Redirect.Type.INHERIT
 

PIPE

added in API level 26
ProcessBuilder.Redirect PIPE

Indicates that subprocess I/O will be connected to the current Java process over a pipe. This is the default handling of subprocess standard I/O.

It will always be true that

 Redirect.PIPE.file() == null &&
 Redirect.PIPE.type() == Redirect.Type.PIPE
 

Public methods

appendTo

added in API level 26
ProcessBuilder.Redirect appendTo (File file)

Returns a redirect to append to the specified file. Each write operation first advances the position to the end of the file and then writes the requested data. Whether the advancement of the position and the writing of the data are done in a single atomic operation is system-dependent and therefore unspecified.

It will always be true that

 Redirect.appendTo(file).file() == file &&
 Redirect.appendTo(file).type() == Redirect.Type.APPEND
 

Parameters
file File: The File for the Redirect.

Returns
ProcessBuilder.Redirect a redirect to append to the specified file

Throws
NullPointerException if the specified file is null

equals

added in API level 26
boolean equals (Object obj)

Compares the specified object with this Redirect for equality. Returns true if and only if the two objects are identical or both objects are Redirect instances of the same type associated with non-null equal File instances.

Parameters
obj Object: the reference object with which to compare.

Returns
boolean true if this object is the same as the obj argument; false otherwise.

file

added in API level 26
File file ()

Returns the File source or destination associated with this redirect, or null if there is no such file.

Returns
File the file associated with this redirect, or null if there is no such file

from

added in API level 26
ProcessBuilder.Redirect from (File file)

Returns a redirect to read from the specified file.

It will always be true that

 Redirect.from(file).file() == file &&
 Redirect.from(file).type() == Redirect.Type.READ
 

Parameters
file File: The File for the Redirect.

Returns
ProcessBuilder.Redirect a redirect to read from the specified file

Throws
NullPointerException if the specified file is null

hashCode

added in API level 26
int hashCode ()

Returns a hash code value for this Redirect.

Returns
int a hash code value for this Redirect

to

added in API level 26
ProcessBuilder.Redirect to (File file)

Returns a redirect to write to the specified file. If the specified file exists when the subprocess is started, its previous contents will be discarded.

It will always be true that

 Redirect.to(file).file() == file &&
 Redirect.to(file).type() == Redirect.Type.WRITE
 

Parameters
file File: The File for the Redirect.

Returns
ProcessBuilder.Redirect a redirect to write to the specified file

Throws
NullPointerException if the specified file is null

type

added in API level 26
ProcessBuilder.Redirect.Type type ()

Returns the type of this Redirect.

Returns
ProcessBuilder.Redirect.Type the type of this Redirect

This site uses cookies to store your preferences for site-specific language and display options.

Get the latest Android developer news and tips that will help you find success on Google Play.

* Required Fields

Hooray!

Follow Google Developers on WeChat

Browse this site in ?

You requested a page in , but your language preference for this site is .

Would you like to change your language preference and browse this site in ? If you want to change your language preference later, use the language menu at the bottom of each page.

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.

Take a short survey?
Help us improve the Android developer experience.
(Sep 2017 survey)