Source Code

API for running native commands in a child process. Clients simply create Processes using the createProcess() method. The new process starts executing immediately.

Process process = createProcess { 
    command = "ls";
    arguments = ["-l"];
    path = home;
};

By default, the standard input, output, and error streams of the new child process are piped to and from the current process by exposing a Writer and Readers.

if (is Reader reader = process.output) {
    while (exists line = reader.readLine()) {
        print(line);
    }
}

The standard input, output, and error streams may be redirected by specifying an Input or Output to createProcess().

Process process = createProcess {
    command = "ls";
    arguments = ["-l"];
    path = home;
    output = OverwriteFileOutput {
        path = home.childPath("out.txt");
    };
    error = AppendFileOutput {
        path = home.childPath("err.txt");
    };
};

The objects currentInput, currentOutput, and currentError allow the standard input, output, and error streams to be redirected to the standard input, output, and error streams of the current virtual machine process.

Process process = createProcess {
    command = "ls";
    arguments = ["-l"];
    path = home;
    output = currentOutput;
    error = currentError;
};

To wait for the child process to terminate, call the waitForExit() method of Process.

Platform: Java
By: Gavin King
Packages
ceylon.process

Public API for the process module.

Dependencies
ceylon.file1.3.2
java.base7

Public API for the process module.

Values
currentEnvironmentSource Codeshared {<String->String>*} currentEnvironment

Environment variables of the current virtual machine process.

currentErrorSource Codeshared currentError currentError

The standard error stream of the current process.

currentInputSource Codeshared currentInput currentInput

The standard input stream of the current process.

currentOutputSource Codeshared currentOutput currentOutput

The standard output stream of the current process.

Functions
createProcessSource Codeshared Process createProcess(String command, {String*} arguments = ..., Path path = ..., Input? input = null, Output? output = null, Error? error = null, String->String* environment)

Create and start a new process, running the given command.

Parameters:
  • command

    The command to be run in the new process, usually the name or path of a program. Command arguments must be passed via the arguments sequence.

  • arguments = {}

    The arguments to the command.

  • path = current

    The directory in which the process runs.

  • input = null

    The source for the standard input stream of the process, or null if the standard input should be piped from the current process.

  • output = null

    The destination for the standard output stream of the process, or null if the standard output should be piped to the current process.

  • error = null

    The destination for the standard output stream of the process, or null if the standard error should be piped to the current process.

  • environment

    Environment variables to pass to the process. By default the process inherits the environment variables of the current virtual machine process.

Interfaces
ErrorSource Codeshared Error

A destination for the standard error stream of a process.

InputSource Codeshared Input

A source for the standard input stream of a process.

OutputSource Codeshared Output

A destination for the standard output stream of a process.

ProcessSource Codeshared Process

Represents a separate native process.

Classes
AppendFileOutputSource Codeshared AppendFileOutput

A stream that appends standard output or standard error to a file.

FileInputSource Codeshared FileInput

A stream that reads standard input from a file.

OverwriteFileOutputSource Codeshared OverwriteFileOutput

A stream that writes standard output or standard error to a file.

currentErrorSource Codeshared currentError

The standard error stream of the current process.

currentInputSource Codeshared currentInput

The standard input stream of the current process.

currentOutputSource Codeshared currentOutput

The standard output stream of the current process.