v0.4.0

Child processes v0.1.0

Source
A started program: waiting for it, killing it, and its standard streams.

ExitStatus

pub struct ExitStatus {
    // private fields
}

How a child process finished. Copy.

Source

Methods

Success

pub func Success(&self) -> bool

Whether the child exited with code zero.

Returns: true for a clean exit

Source

Code

pub func Code(&self) -> int32?

The code the child exited with, or none when a signal ended it.

Returns: the exit code

Source

Signal

pub func Signal(&self) -> int32?

The signal that ended the child on a Unix system, or none when it exited. Never present on Windows.

Returns: the signal number

Source

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.

Source

Methods

Close

pub func Close(&var self)

Closes the pipe now rather than when the writer is dropped. Closing it twice does nothing.

Source

Implements Writer

PipeWriter conforms to Writer.

Write

pub func Write(
    &var self,
    bytes: char8[..]
) -> uint throws IoError

Writes some of bytes into the pipe, waiting while it is full.

NameTypeDescription
byteschar8[..]the bytes to write

Returns: how many were written, or fails, with a broken pipe once the child closed its end

Source

Flush

pub func Flush(&var self) throws IoError

Does nothing: a pipe keeps no buffer of its own.

Returns: nothing

Source

Destructor

~PipeWriter

func ~PipeWriter(&var self)

Source

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.

Source

Methods

Close

pub func Close(&var self)

Closes the pipe now rather than when the reader is dropped. Closing it twice does nothing.

Source

Implements Reader

PipeReader conforms to Reader.

Read

pub func Read(
    &var self,
    into: var char8[..]
) -> uint throws IoError

Reads what the child has written so far into into, waiting while it has written nothing.

NameTypeDescription
intovar 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

Source

Destructor

~PipeReader

func ~PipeReader(&var self)

Source

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.

Source

Methods

Id

pub func Id(&self) -> uint32

The child's process identifier.

Returns: the identifier

Source

TakeInput

pub func TakeInput(&var self) -> 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

Source

TakeOutput

pub func TakeOutput(&var self) -> 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

Source

TakeError

pub func TakeError(&var self) -> 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

Source

Wait

pub func Wait(&var self) -> ExitStatus throws 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

Source

TryWait

pub func TryWait(&var self) -> ExitStatus? throws IoError

How the child finished, or none while it still runs, without waiting.

Returns: the status once the child has finished

Source

Kill

pub func Kill(&var self) throws 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

Source

Destructor

~Child

func ~Child(&var self)

Source