Skip to content
FutureBlitz

    Install

    Import std.os.process_command

    std.os.process_command

    Command, a program to start, with its arguments, environment, folder, and streams, and no shell, so each argument reaches it as it is, on every OS: Spawn starts it beside this program, and Output and Status wait for it to end. Process.Arguments gives this program's own.

    std/os/process_command.fb

    Types

    Stdio enum

    Public Enum Stdio

    Where a child's stream goes.

    std/os/process_command.fb, line 20

    • INHERIT enum member #

      To this program's own.

    • PIPED enum member #

      Through a pipe that this program writes or reads.

    • NONE enum member #

      Nowhere, so its stdin has nothing, and what it writes is dropped.

    ProcessOutput struct

    Public Struct ProcessOutput

    What a child wrote to its stdout and stderr, and how it ended.

    std/os/process_command.fb, line 30

    • Public ReadOnly Field Status: ExitStatus field #

      How it ended.

    • Public ReadOnly Field Stdout: UInt8[] field #

      What it wrote to its stdout.

    • Public ReadOnly Field Stderr: UInt8[] field #

      What it wrote to its stderr.

    • Public Property Text: String property #

      Stdout as text, its UTF-8, with U+FFFD for each byte that doesn't start well-formed UTF-8.

    • Public Property ErrorText: String property #

      Stderr as text, as Text is.

    Command class

    Public Class Command

    A program to start, and what it starts with. It's found as a path, from the Folder it runs in when it's relative, or by its name on the PATH it gets, never in a current folder; on Windows, with .com or .exe after the name too. Its methods give the Command back, so they chain: Command("git").Arg("log").Folder(repo).Output(). It can start the program any number of times.

    std/os/process_command.fb, line 59

    • Public New(program: String) constructor #

      A new ProcessCommand that runs program, with no arguments yet.

    • Public Method Arg(argument: String): Command method #

      Adds an argument, which the program gets as it is: nothing splits it, or reads quotes or anything else in it. On Windows, a .bat or .cmd file runs in cmd.exe, which gets one as Rust gives it there, so nothing in it runs: in quotes when it has anything but letters, digits, and #$*+-./:?@_, with each quote doubled, and every % kept from expanding, so the batch file reads it with %~1. One with a line break, which cmd.exe can't take, throws an IOError as it starts.

    • Public Method Args(arguments: String[]): Command method #

      Adds the arguments, in order, as Arg does.

    • Public Method Env(name: String, value: String): Command method #

      Sets the variable name to value for the program, whose environment is otherwise this program's. On Windows a name is the same in any case, so "Path" is "PATH".

    • Public Method Unset(name: String): Command method #

      Takes the variable name out of the program's environment. On Windows, the ones every program needs, PATH, SYSTEMROOT, TEMP, and the like, stay, with this program's values.

    • Public Method ClearEnv(): Command method #

      Starts the program with no variables but the ones Env sets after this, and on Windows the ones every program needs, as Unset leaves them.

    • Public Method Folder(folder: String): Command method #

      Runs the program in folder, not this program's current one.

    • Public Method Stdin(how: Stdio): Command method #

      Where its stdin comes from.

    • Public Method Stdout(how: Stdio): Command method #

      Where its stdout goes.

    • Public Method Stderr(how: Stdio): Command method #

      Where its stderr goes.

    • @PanicsAtCaller Public Method Spawn(): Child Throws IOError method #

      Starts the program, which runs beside this one, and gives its Child, once what this program printed is out. Its streams are this program's unless Stdin, Stdout, or Stderr said otherwise. Throws an IOError when it can't start, one of NOT_FOUND for a program that isn't there. Panics when a text has a NUL, or a variable's name is empty or has an '=', which none can.

    • @PanicsAtCaller Public Method Output(): ProcessOutput Throws IOError method #

      Runs the program to its end, and gives what it wrote to its stdout and stderr, and how it ended. Its stdin has nothing, or closes at once when Stdin pipes it. Throws and panics as Spawn does.

    • @PanicsAtCaller Public Async Method OutputAsync(): ProcessOutput Throws IOError method #

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

    • @PanicsAtCaller Public Method Status(): ExitStatus Throws IOError method #

      Runs the program to its end, with this program's streams unless Stdin, Stdout, or Stderr said otherwise, and gives how it ended. Throws and panics as Spawn does.

    • @PanicsAtCaller Public Async Method StatusAsync(): ExitStatus Throws IOError method #

      Status's Async twin.

    Extends

    Process extend

    Extend Process

    No doc comment.

    std/os/process_command.fb, line 219

    • Public Static Method Arguments(): String[] static method #

      The program's arguments, after its own name, as what started it gave them. On Windows, they're its command line, split as a C program splits it.

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