Cmd
Cmd
Represents a command to be executed in a child process.
Output
Represents the output of a command.
Output is a record:
{ status : Result I32 InternalIOErr.IOErr, stdout : List U8, stderr : List U8, }
new : Str -> Cmd
Create a new command to execute the given program in a child process.
arg : Cmd, Str -> Cmd
Add a single argument to the command.
! Shell features like variable subsitition (e.g. $FOO
), glob patterns (e.g. *.txt
), ... are not available.
# Represent the command "ls -l" Cmd.new("ls") |> Cmd.arg("-l")
args : Cmd, List Str -> Cmd
Add multiple arguments to the command.
! Shell features like variable subsitition (e.g. $FOO
), glob patterns (e.g. *.txt
), ... are not available.
# Represent the command "ls -l -a" Cmd.new("ls") |> Cmd.args(["-l", "-a"])
env :
Cmd,
Str,
Str
-> Cmd
Add a single environment variable to the command.
# Run "env" and add the environment variable "FOO" with value "BAR" Cmd.new("env") |> Cmd.env("FOO", "BAR")
envs :
Cmd, List
(
Str,
Str
)
-> Cmd
Add multiple environment variables to the command.
# Run "env" and add the variables "FOO" and "BAZ" Cmd.new("env") |> Cmd.envs([("FOO", "BAR"), ("BAZ", "DUCK")])
clear_envs : Cmd -> Cmd
Clear all environment variables, and prevent inheriting from parent, only the environment variables provided to command are available to the child.
# Represents "env" with only "FOO" environment variable set Cmd.new("env") |> Cmd.clear_envs |> Cmd.env("FOO", "BAR")
output! : Cmd => Output
Execute command and capture stdout, stderr and the exit code in Output
.
Stdin is not inherited from the parent and any attempt by the child process to read from the stdin stream will result in the stream immediately closing.
status! : Cmd => Result I32 [CmdStatusErr InternalIOErr.IOErr]
Execute command and inherit stdin, stdout and stderr from parent
exec! : Str, List Str => Result {} [CmdStatusErr InternalIOErr.IOErr]
Execute command and inherit stdin, stdout and stderr from parent
# Call echo to print "hello world" Cmd.exec!("echo", ["hello world"])