std.process
The running program’s arguments, environment and exit code, and the programs it runs.
main may return () (exit code 0), an ExitCode, or a Result of either. An Err is written to standard error and exits with 1.
ExitCode
Section titled “ExitCode”type ExitCode = Int where 0 <= it && it <= 255A process exit code from 0 to 255. 0 is success.
Process
Section titled “Process”capability Process {}The running process. Only the runtime makes one, for main.
FakeEnvironment
Section titled “FakeEnvironment”type FakeEnvironment = { arguments: List[String], variables: Dict[String, String],}An environment for tests.
RunMode
Section titled “RunMode”type RunMode = // `strata run`, or a built executable | Running // `strata test` | Testing // `strata run --trace` | TracingHow the program is being run.
main or a test may ask for it only when strata.toml sets mode = true
under [run]. Otherwise a program behaves the same wherever it runs.
Finished
Section titled “Finished”type Finished = { code: Int, out: String, err: String }A finished program’s exit code and output. A program killed by a signal has code 128 + the signal.
RunOptions
Section titled “RunOptions”type RunOptions = { /// Its standard input. `""` is none. input: String = "", /// Environment variables set on top of this program's own, such as `("GIT_DIR", "x")`. env: List[(String, String)] = [], /// Gives it this program's terminal, for an editor or output shown as it comes. `Finished` then holds only the exit code. terminal: Bool = false,}How a program is run, besides its arguments and folder.
Launcher
Section titled “Launcher”capability Launcher {}The real system’s programs. Only the runtime makes one, for main or a
test that names it.
FinishedBytes
Section titled “FinishedBytes”type FinishedBytes = { code: Int, out: List[Int], err: List[Int] }A finished program’s exit code and output, as bytes (run_bytes), each
an Int from 0 to 255.
Traits
Section titled “Traits”Environment
Section titled “Environment”capability trait Environment { /// The command-line arguments, without the program's own name. Bytes that aren't UTF-8 read as U+FFFD. fn args(self) -> List[String] /// The value of an environment variable, if it is set. Bytes that aren't UTF-8 read as U+FFFD. fn var(self, name: String) -> Option[String] /// The current folder, absolute. fn current_dir(self) -> String}What the program was started with: the real process or a stand-in.
Commands
Section titled “Commands”capability trait Commands { /// Runs `program` with `args` in the folder `dir` and waits for it. /// - `program` is looked up in `PATH` unless it holds a `/`. No shell is involved. /// - `dir` is `""` for the current folder. /// - Its standard input is empty. /// - `Err` when it can't be started (no such program or folder, or a NUL byte in an argument), or when its output isn't UTF-8 text (`run_bytes` reads it as bytes). A program that starts and fails is `Ok` with its exit code. fn run( mut self, program: String, args: List[String], dir: String, ) -> Result[Finished, String] ensures match it { Ok(f) => 0 <= f.code, Err(_) => true, } /// `run`, with standard input, environment and terminal set by `options`. fn run_with( mut self, program: String, args: List[String], dir: String, options: RunOptions, ) -> Result[Finished, String] ensures match it { Ok(f) => 0 <= f.code, Err(_) => true, } /// `run_with`, its output and error output as bytes, whether or not they /// are UTF-8 text: for a program that writes binary data. fn run_bytes( mut self, program: String, args: List[String], dir: String, options: RunOptions, ) -> Result[FinishedBytes, String] ensures match it { Ok(f) => 0 <= f.code, Err(_) => true, }}Starts other programs: Launcher for the real system, or a mock in a
test.
Functions
Section titled “Functions”fake_environment
Section titled “fake_environment”fn fake_environment( arguments: List[String], variables: List[(String, String)],) -> FakeEnvironmentA test environment with these arguments and variables.
Implementations
Section titled “Implementations”impl Environment for Processimpl Environment for FakeEnvironmentimpl Commands for Launcher