API for running native commands in a child process.
Clients simply create Process
es 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
Reader
s.
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
.
Packages | |
ceylon.process | Public API for the process module. |
Dependencies | ||
ceylon.file | 1.3.3 | |
java.base | 7 |
Public API for the process module.
Values | |
currentEnvironment | Source Codeshared {<String->String>*} currentEnvironment Environment variables of the current virtual machine process. |
currentError | Source Codeshared currentError currentError The standard error stream of the current process. |
currentInput | Source Codeshared currentInput currentInput The standard input stream of the current process. |
currentOutput | Source Codeshared currentOutput currentOutput The standard output stream of the current process. |
Functions | |
createProcess | Source 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:
|
Interfaces | |
Error | Source Codeshared Error A destination for the standard error stream of a process. |
Input | Source Codeshared Input A source for the standard input stream of a process. |
Output | Source Codeshared Output A destination for the standard output stream of a process. |
Process | Source Codeshared Process Represents a separate native process. |
Classes | |
AppendFileOutput | Source Codeshared AppendFileOutput A stream that appends standard output or standard error to a file. |
FileInput | Source Codeshared FileInput A stream that reads standard input from a file. |
OverwriteFileOutput | Source Codeshared OverwriteFileOutput A stream that writes standard output or standard error to a file. |
currentError | Source Codeshared currentError The standard error stream of the current process. |
currentInput | Source Codeshared currentInput The standard input stream of the current process. |
currentOutput | Source Codeshared currentOutput The standard output stream of the current process. |