Java types needed to run processes. Because the associated classes are in java.lang, the stuff here would belong into package frege.java.Lang, however, it does not seem justified to have it imported in each and every program.
The type Process provides methods for performing input from the process, performing output to the process, waiting for the process to complete, checking the exit status of the process, and destroying (killing) the process.
An instance of Process can be obtained from the Process.exec or ProcessBuilder.start methods.
Kills the subprocess. The subprocess represented by this Process object is forcibly terminated.
Process.exec cmdarray envp dir Process.exec "command"
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 Maybe.Nothing, 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.
The working directory of the new subprocess is specified by dir. If dir is Maybe.Nothing, the subprocess inherits the current working directory of the current process.
If a security manager exists, its 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:
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.
Process.exec cmdarray envp dir Process.exec "command"
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 Maybe.Nothing, 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.
The working directory of the new subprocess is specified by dir. If dir is Maybe.Nothing, the subprocess inherits the current working directory of the current process.
If a security manager exists, its 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:
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.
Process.exec cmdarray envp dir Process.exec "command"
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 Maybe.Nothing, 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.
The working directory of the new subprocess is specified by dir. If dir is Maybe.Nothing, the subprocess inherits the current working directory of the current process.
If a security manager exists, its 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:
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.
Returns the exit value for the subprocess represented by this Process object.
By convention, the value 0 indicates normal termination.
Returns the input stream connected to the standard error output of the subprocess. The stream obtains data piped from the error output of the process represented by this Process object.
If the standard error of the subprocess has been redirected using ProcessBuilder.redirectError or ProcessBuilder.redirectErrorStream then this method will return an input stream, for which the InputStream.read method always returns -1, the InputStream.available method returns always 0 and the InputStream.close method does nothing.
Returns the input stream connected to the standard output of the subprocess. The stream obtains data piped from the standard output of the process represented by this Process object.
If the standard output of the subprocess has been redirected using ProcessBuilder.redirectOutput then this method will return an input stream, for which the InputStream.read method always returns -1, the InputStream.available method returns always 0 and the InputStream.close method does nothing.
Otherwise, if the standard error of the subprocess has been redirected using ProcessBuilder.redirectErrorStream then the input stream returned by this method will receive the merged standard output and the standard error of the subprocess.
Returns the output stream connected to the standard input of the subprocess. Output to the stream is piped into the standard input of the process represented by this Process object.
If the standard input of the subprocess has been redirected using ProcessBuilder.redirectInput then this method will return an output stream for which the OutputStream.write method always throws IOException and the OutputStream.close method does nothing.
Causes the current thread to wait, if necessary, until the process represented by this Process object has terminated. This method returns immediately if the subprocess has already terminated. If the subprocess has not yet terminated, the calling thread will be blocked until the subprocess exits.
Convenience function to get an UTF-8 encoded PrintWriter that is connected to the standard input of a Process.
Convenience function to get an UTF-8 encoded BufferedReader that is connected to the standard output of a Process.
Convenience function to get an UTF-8 encoded BufferedReader that is connected to the standard error of a Process.
Represents a source of subprocess input or a destination of subprocess output. Each Redirect is one of the following:
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.
Returns the File source or destination associated with this redirect, or null if there is no such file.
Redirect to read from the specified File.
nowarn: We know this is constant
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).
nowarn: We know this is constant
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.
Redirect to write to the specified file, discarding previous content, if any.
The ProcessBuilder type is used to create operating system processes.
Each ProcessBuilder manages a collection of process attributes. The ProcessBuilder.start method creates a new Process instance with those attributes. The ProcessBuilder.start method can be invoked repeatedly from the same instance to create new subprocesses with identical or related attributes.
The following attributes are being managed:
Modifying a process builder's attributes will affect processes subsequently started by that object's start() method, but will never affect previously started processes or the Java process itself.
Most error checking is performed by the start() method. It is possible to modify the state of an object so that start() will fail. For example, setting the command attribute to an empty list will not throw an exception unless start() is invoked.
Note that this type is not synchronized. If multiple threads access a ProcessBuilder instance concurrently, and at least one of the threads modifies one of the attributes structurally, it must be synchronized externally.
set the working directory
inherit the standard input, output and error from the current process
create a ProcessBuilder passing the command line as list.
create a ProcessBuilder passing the command line as array
redirect standard error
set the redirectErrorStream property
redirect standard error
redirect standard error
redirect standard input
redirect standard input
redirect standard input
redirect standard output
redirect standard output
redirect standard output
start the new process
For details see Process.exec
ProcessBuilder.redirectOutput𝖇, ProcessBuilder.directory, ProcessBuilder.redirectError𝖇, ProcessBuilder.redirectInput𝖇
ProcessBuilder.redirectOutput𝖆, ProcessBuilder.redirectInput𝖆, ProcessBuilder.redirectError𝖆
Process.exec, ProcessBuilder.redirectOutput, ProcessBuilder.redirectInput, ProcessBuilder.redirectError