Child processes v0.1.0
ExitStatus
pub struct ExitStatus {
// private fields
}
How a child process finished. Copy.
Methods
Success
pub func Success(self: &ExitStatus) -> bool
Whether the child exited with code zero.
Returns: true for a clean exit
Code
pub func Code(self: &ExitStatus) -> int32?
The code the child exited with, or none when a signal ended it.
Returns: the exit code
Signal
pub func Signal(self: &ExitStatus) -> int32?
The signal that ended the child on a Unix system, or none when it exited. Never present on Windows.
Returns: the signal number
PipeWriter
pub struct PipeWriter {
// private fields
}
The writing end of a pipe into a child's standard input. Closing it, by dropping it, ends the child's input. A pipe end is not copied.
Methods
Close
pub func Close(self: &var PipeWriter)
Closes the pipe now rather than when the writer is dropped. Closing it twice does nothing.
Implements Writer
PipeWriter conforms to Writer.
Write
pub func Write(
self: &var PipeWriter,
bytes: char8[..]
) -> uint ! IoError
Writes some of bytes into the pipe, waiting while it is full.
| Name | Type | Description |
|---|---|---|
bytes | char8[..] | the bytes to write |
Returns: how many were written, or fails, with a broken pipe once the child closed its end
Flush
pub func Flush(self: &var PipeWriter) -> ! IoError
Does nothing: a pipe keeps no buffer of its own.
Returns: nothing
Destructor
~PipeWriter
func ~PipeWriter(self: &var PipeWriter)
PipeReader
pub struct PipeReader {
// private fields
}
The reading end of a pipe from a child's standard output or error. A read past what the child wrote, once it has
closed its end, fails with EndOfStream. A pipe end is not copied.
Methods
Close
pub func Close(self: &var PipeReader)
Closes the pipe now rather than when the reader is dropped. Closing it twice does nothing.
Implements Reader
PipeReader conforms to Reader.
Read
pub func Read(
self: &var PipeReader,
into: var char8[..]
) -> uint ! IoError
Reads what the child has written so far into into, waiting while it has written nothing.
| Name | Type | Description |
|---|---|---|
into | var char8[..] | where to put the bytes |
Returns: how many were read, or fails with EndOfStream once the child closed its end and all was read
Destructor
~PipeReader
func ~PipeReader(self: &var PipeReader)
Child
pub struct Child {
// private fields
}
A child process this one started. Wait for it to learn how it finished. Dropping a child that was not waited for neither waits for nor stops it; on the Unix systems its exit status then stays with the system until this process ends. A child is not copied.
Methods
Id
pub func Id(self: &Child) -> uint32
The child's process identifier.
Returns: the identifier
TakeInput
pub func TakeInput(self: &var Child) -> PipeWriter?
The pipe into the child's standard input, when it was started with Stdio::Pipe there and the pipe was not
taken before.
Returns: the writer, which the caller now owns
TakeOutput
pub func TakeOutput(self: &var Child) -> PipeReader?
The pipe from the child's standard output, when it was started with Stdio::Pipe there and the pipe was not
taken before.
Returns: the reader, which the caller now owns
TakeError
pub func TakeError(self: &var Child) -> PipeReader?
The pipe from the child's standard error, when it was started with Stdio::Pipe there and the pipe was not
taken before.
Returns: the reader, which the caller now owns
Wait
pub func Wait(self: &var Child) -> ExitStatus ! IoError
Waits for the child to finish and returns how it did. The pipe into its input, if still held, is closed first, so a child reading its input to the end is not left waiting for more. Waiting again returns the same status.
Returns: how the child finished
TryWait
pub func TryWait(self: &var Child) -> ExitStatus? ! IoError
How the child finished, or none while it still runs, without waiting.
Returns: the status once the child has finished
Kill
pub func Kill(self: &var Child) -> ! IoError
Ends the child at once: with SIGKILL on the Unix systems, and with exit code 1 on Windows. Killing a child
that has already finished does nothing. Wait for it afterwards to learn its status.
Returns: nothing, or fails when the system refused
Destructor
~Child
func ~Child(self: &var Child)