Module Java.lang.Processes

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.

Imports

Table of Content

Definitions

data Process = native java.lang.Process

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.

Member Functions

destroyMutableIO ProcessIO ()
native destroy

Kills the subprocess. The subprocess represented by this Process object is forcibly terminated.

execArrayOf RealWorld StringMaybe (ArrayOf RealWorld String) → Maybe (MutableIO File) → STMutable RealWorld Process
          throws IOException
      | StringSTMutable RealWorld Process
          throws IOException
native java.lang.Runtime.getRuntime().exec
 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:

  • The operating system program file was not found.
  • Access to the program file was denied.
  • The working directory does not exist.

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:
A new Process object for managing the subprocess
Throws:
exec𝖆ArrayOf RealWorld StringMaybe (ArrayOf RealWorld String)Maybe (MutableIO File)STMutable RealWorld Process
native java.lang.Runtime.getRuntime().exec  throws IOException  overloads exec
 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:

  • The operating system program file was not found.
  • Access to the program file was denied.
  • The working directory does not exist.

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:
A new Process object for managing the subprocess
Throws:
exec𝖇StringSTMutable RealWorld Process
native java.lang.Runtime.getRuntime().exec  throws IOException  overloads exec
 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:

  • The operating system program file was not found.
  • Access to the program file was denied.
  • The working directory does not exist.

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:
A new Process object for managing the subprocess
Throws:
exitValueMutableIO ProcessIO Int
native exitValue  throws IllegalThreadStateException

Returns the exit value for the subprocess represented by this Process object.

By convention, the value 0 indicates normal termination.

getErrorStreamMutableIO ProcessSTMutable RealWorld InputStream
native getErrorStream

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.

getInputStreamMutableIO ProcessSTMutable RealWorld InputStream
native getInputStream

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.

getOutputStreamMutableIO ProcessSTMutable RealWorld OutputStream
native getOutputStream

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.

waitForMutableIO ProcessIO Int
native waitFor  throws InterruptedException

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.

Returns:
the exit value of the subprocess represented by this Process object. By convention, the value 0 indicates normal termination.
Throws:
InterruptedException if the current Thread is interrupted by another Thread while it is waiting.
stdinWriterMutableIO ProcessSTMutable RealWorld PrintWriter

Convenience function to get an UTF-8 encoded PrintWriter that is connected to the standard input of a Process.

stdoutReaderMutableIO ProcessSTMutable RealWorld BufferedReader

Convenience function to get an UTF-8 encoded BufferedReader that is connected to the standard output of a Process.

stderrReaderMutableIO ProcessSTMutable RealWorld BufferedReader

Convenience function to get an UTF-8 encoded BufferedReader that is connected to the standard error of a Process.

data Redirect = native java.lang.ProcessBuilder.Redirect

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

Member Functions

appendToMutableIO FileSTMutable RealWorld Redirect
native java.lang.ProcessBuilder.Redirect.appendTo

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.

fileMutableIO RedirectIO (Maybe (MutableIO File))
native file

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

fromMutableIO FileSTMutable RealWorld Redirect
native java.lang.ProcessBuilder.Redirect.from

Redirect to read from the specified File.

inheritMutableIO Redirect
native java.lang.ProcessBuilder.Redirect.INHERIT

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).

pipeMutableIO Redirect
native java.lang.ProcessBuilder.Redirect.PIPE

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.

toMutableIO FileSTMutable RealWorld Redirect
native java.lang.ProcessBuilder.Redirect.to

Redirect to write to the specified file, discarding previous content, if any.

data ProcessBuilder = native java.lang.ProcessBuilder

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.

Member Functions

directoryMutableIO ProcessBuilderMutableIO FileSTMutable RealWorld ProcessBuilder
native directory

set the working directory

inheritIOMutableIO ProcessBuilderSTMutable RealWorld ProcessBuilder
native inheritIO

inherit the standard input, output and error from the current process

new ∷ [String] → STMutable RealWorld ProcessBuilder

create a ProcessBuilder passing the command line as list.

newFromArrayArrayOf RealWorld StringSTMutable RealWorld ProcessBuilder
native new

create a ProcessBuilder passing the command line as array

redirectErrorMutableIO ProcessBuilderMutableIO RedirectSTMutable RealWorld ProcessBuilder
               | MutableIO ProcessBuilderMutableIO FileSTMutable RealWorld ProcessBuilder
native redirectError

redirect standard error

redirectErrorStreamMutableIO ProcessBuilderBoolSTMutable RealWorld ProcessBuilder
native redirectErrorStream

set the redirectErrorStream property

redirectError𝖆MutableIO ProcessBuilderMutableIO RedirectSTMutable RealWorld ProcessBuilder
native redirectError  overloads redirectError

redirect standard error

redirectError𝖇MutableIO ProcessBuilderMutableIO FileSTMutable RealWorld ProcessBuilder
native redirectError  overloads redirectError

redirect standard error

redirectInputMutableIO ProcessBuilderMutableIO RedirectSTMutable RealWorld ProcessBuilder
               | MutableIO ProcessBuilderMutableIO FileSTMutable RealWorld ProcessBuilder
native redirectInput

redirect standard input

redirectInput𝖆MutableIO ProcessBuilderMutableIO RedirectSTMutable RealWorld ProcessBuilder
native redirectInput  overloads redirectInput

redirect standard input

redirectInput𝖇MutableIO ProcessBuilderMutableIO FileSTMutable RealWorld ProcessBuilder
native redirectInput  overloads redirectInput

redirect standard input

redirectOutputMutableIO ProcessBuilderMutableIO RedirectSTMutable RealWorld ProcessBuilder
                | MutableIO ProcessBuilderMutableIO FileSTMutable RealWorld ProcessBuilder
native redirectOutput

redirect standard output

redirectOutput𝖆MutableIO ProcessBuilderMutableIO RedirectSTMutable RealWorld ProcessBuilder
native redirectOutput  overloads redirectOutput

redirect standard output

redirectOutput𝖇MutableIO ProcessBuilderMutableIO FileSTMutable RealWorld ProcessBuilder
native redirectOutput  overloads redirectOutput

redirect standard output

startMutableIO ProcessBuilderSTMutable RealWorld Process
native start  throws IOException

start the new process

For details see Process.exec

Functions and Values by Type

ArrayOf RealWorld StringMaybe (ArrayOf RealWorld String) → Maybe (MutableIO File) → STMutable RealWorld Process

Process.exec𝖆

ArrayOf RealWorld StringSTMutable RealWorld ProcessBuilder

ProcessBuilder.newFromArray

MutableIO FileSTMutable RealWorld Redirect

Redirect.to, Redirect.appendTo, Redirect.from

MutableIO ProcessSTMutable RealWorld BufferedReader

stderrReader, stdoutReader

MutableIO ProcessSTMutable RealWorld InputStream

Process.getErrorStream, Process.getInputStream

MutableIO ProcessSTMutable RealWorld OutputStream

Process.getOutputStream

MutableIO ProcessSTMutable RealWorld PrintWriter

stdinWriter

MutableIO ProcessIO ()

Process.destroy

MutableIO ProcessIO Int

Process.waitFor, Process.exitValue

MutableIO ProcessBuilderMutableIO FileSTMutable RealWorld ProcessBuilder

ProcessBuilder.redirectOutput𝖇, ProcessBuilder.directory, ProcessBuilder.redirectError𝖇, ProcessBuilder.redirectInput𝖇

MutableIO ProcessBuilderMutableIO RedirectSTMutable RealWorld ProcessBuilder

ProcessBuilder.redirectOutput𝖆, ProcessBuilder.redirectInput𝖆, ProcessBuilder.redirectError𝖆

MutableIO ProcessBuilderBoolSTMutable RealWorld ProcessBuilder

ProcessBuilder.redirectErrorStream

MutableIO ProcessBuilderSTMutable RealWorld Process

ProcessBuilder.start

MutableIO ProcessBuilderSTMutable RealWorld ProcessBuilder

ProcessBuilder.inheritIO

MutableIO RedirectIO (Maybe (MutableIO File))

Redirect.file

StringSTMutable RealWorld Process

Process.exec𝖇

[String] → STMutable RealWorld ProcessBuilder

ProcessBuilder.new

MutableIO Redirect

Redirect.inherit, Redirect.pipe

ω

Process.exec, ProcessBuilder.redirectOutput, ProcessBuilder.redirectInput, ProcessBuilder.redirectError

Valid HTML 4.01 Strict