Early preview: syntax, standard library APIs, and tooling may change.

Working ProgramsProcesses and Environment

Processes and Environment

Use explicit imports for environment and process APIs.

Env Vars

system.getenv returns Option[String].

mode: String = getenv("APP_MODE").get_or("dev")

Process Helpers

run_command accepts a ProcessCommand. Spawn and I/O failures return Err; Ok includes a typed exit code, signal, or timeout plus stdout and stderr as Bytes. The older run helper remains available.

import:
	process: ProcessExit(Exited, Signaled, TimedOut), command, run_command
	units: seconds


func main(args: List[String]) -> Int:
	request = { command("printf", ["%s", "ok"]) | timeout = Some(seconds(2)) }
	match run_command(request):
		Ok(out):
			print(out.stdout.to_string())
			match out.exit:
				Exited(code): code
				Signaled(signal):
					print_error("process interrupted by signal ${signal}")
					1
				TimedOut:
					print_error("process timed out")
					1
		Err(error):
			print_error(error)
			1

Shell Safety

Separate arguments avoid shell parsing, but the called program still has its own syntax. Use a fixed printf format for user data. Reserve process.shell for trusted scripts.

P.run_command(P.command("printf", ["%s", value]))
-- Prefer this over building a shell string.

Example

env-process.brp
import:
	process: ProcessExit(Exited, Signaled, TimedOut), command, run_command
	system: getenv
	units: seconds


func main(args: List[String]) -> Int:
	config: String = getenv("APP_MODE").get_or("dev")

	request = { command("printf", ["%s", config]) | timeout = Some(seconds(2)) }
	match run_command(request):
		Ok(out):
			print(out.stdout.to_string()) -- with APP_MODE=docs, prints: docs
			match out.exit:
				Exited(code): code
				Signaled(signal):
					print_error("process interrupted by signal ${signal}")
					1
				TimedOut:
					print_error("process timed out")
					1
		Err(error):
			print_error(error)
			1

Try it

terminal
blorp run env-process.brp