Skip to content
FutureBlitz

    Install

    Import std.os.process_child

    std.os.process_child

    A running child process: its streams, waiting for it, and ending it.

    Child, a program that a Command started, which runs beside this one: its Id, its piped streams, a Writer to its stdin and Readers of its stdout and stderr, and Wait, TryWait, and Kill, with the ExitStatus that says how it ended.

    Examples

    Local child = Try Command("sort").Stdin(Stdio.PIPED).Stdout(Stdio.PIPED).Spawn()
    Local input = child.Stdin
    Local output = child.Stdout
    If input == Null || output == Null Then Return
    Try input.WriteText("pear\napple\n")
    input.Close()
    Print(Try ReadAllText(output))
    Print(child.Wait())

    std/os/process_child.fb

    Types

    ExitStatus struct

    Public Struct ExitStatus Implements Printable

    How a child ended: with the code it exited with, or by a signal, as Kill ends one.

    std/os/process_child.fb, line 45

    • Public ReadOnly Field Code: Int64? field #

      The code it exited with, which on Windows is from 0 to 4294967295, or Null when a signal ended it.

    • Public ReadOnly Field Signal: Int? field #

      The signal that ended it, as 9 for Kill, on Windows too, or Null when it exited.

    • Public Property Success: Bool property #

      Whether it exited with 0, which says it went well.

    • Public Method ToString(): String method #

      How it ended, as "exit code 0" or "signal 9".

    Child class

    Public Class Child

    A program that a Command started, which runs beside this one until it ends, whether or not this program waits for it. Letting go of it, and of its streams, closes its pipes, but doesn't end it.

    std/os/process_child.fb, line 77

    • Public ReadOnly Field Stdin: ChildInput? field #

      Its stdin, when the Command piped it, a Writer to what the child reads.

    • Public ReadOnly Field Stdout: ChildOutput? field #

      Its stdout, when the Command piped it, a Reader of what the child writes there.

    • Public ReadOnly Field Stderr: ChildOutput? field #

      Its stderr, when the Command piped it.

    • Public Property Id: Int64 property #

      The OS's number for its process.

    • Public Method Wait(): ExitStatus method #

      Waits for it to end, and gives how it did. Its stdin closes first, so a child that reads to its end doesn't wait for more.

    • Public Async Method WaitAsync(): ExitStatus method #

      Wait's Async twin, which waits on the main thread instead of blocking it.

    • Public Method TryWait(): ExitStatus? method #

      How it ended, or Null while it runs.

    • Public Method Kill() Throws IOError method #

      Ends it at once, unless it's ended already: by SIGKILL, or on Windows TerminateProcess, either way with Signal 9. Throws an IOError when the OS won't.

    ChildInput class

    Public Class ChildInput Implements Writer

    A child's stdin, which writes to what it reads. Bytes go to the child as they're written, and Write returns once they have.

    std/os/process_child.fb, line 134

    • Public Method Write(from: Buffer<UInt8>) Throws IOError method #

      Writes from's bytes to the child's stdin. Throws an IOError once the stream is closed, or the child has gone.

    • Public Async Method WriteAsync(from: Buffer<UInt8>) Throws IOError method #

      Write's Async twin, which writes on the I/O thread while the main thread goes on.

    • Public Method Close() method #

      Closes it once what's written has gone, so the child reads to its end. Closing it again does nothing.

    ChildOutput class

    Public Class ChildOutput Implements Reader

    A child's stdout or stderr, which reads what it writes there, as it comes, until it ends or closes it.

    std/os/process_child.fb, line 175

    • Public Method Read(into: Buffer<UInt8>): Int64 Throws IOError method #

      Reads up to into.Count bytes of what the child wrote into the start of into, waiting while it's written nothing new, and gives how many, or 0 once the child has closed the stream.

    • Public Async Method ReadAsync(into: Buffer<UInt8>): Int64 Throws IOError method #

      Read's Async twin, which waits on the I/O thread while the main thread goes on.

    Report an issue with this page or with FutureBlitz on GitHub.