Clear all environment variables before running the command.
Only environment variables added via env or envs will be available.
Useful if you want a clean command run that does not behave unexpectedly if the user has some env var set.
Set the child working directory without changing the parent directory.
Use an absolute executable path or a bare PATH name: resolving a relative
executable against cwd is platform-specific.
Let the child use the parent's standard input, output and error, however
the command is run. With [run!] this gives the exit status of a command
that prints to the terminal:
status = Cmd.new("roc").args(["check", "main.roc"]).inherit_stdio().run!()?.status
Stop the command when it has run for longer than duration. The deadline
covers the whole run, including reading the rest of its output.
A command that reaches its deadline is killed, and the result is
Err(CmdErr(TimedOut(partial))) with the output captured so far. That is
also what [Child.wait!] and [Child.poll!] return for a child started with
[spawn!]. When timeout is not called there is no deadline;
Duration.zero expires immediately.
Limit how many bytes of standard output and standard error are captured,
counted together. The default is MaxBytes(16777216), 16 MiB.
A command that prints more is killed, and the result is
Err(CmdErr(OutputLimitExceeded(partial))) with the output captured up to
the limit. NoLimit captures whatever the command prints.
Limit how many bytes of Pipe output may wait to be read with
[Child.read!], counted over both streams (default 1 MiB). A child that
gets further ahead of its reader is killed, and [Child.wait!] returns
Err(CmdErr(OutputLimitExceeded(partial))).
capture! : Cmd => Try(Str, [CmdErr(Err), BadExitStatus(Output), BadUtf8({ problem : Utf8Problem, index : U64 })])
Run the command, require it to succeed, and return its standard output as
text.
Standard output is captured unless the command sets it. Standard input and
standard error are inherited unless the command sets them, so warnings
still reach the terminal, as with a shell's $(..). Any status other than
exit code 0 is Err(BadExitStatus(output)), and output that is not UTF-8
is Err(BadUtf8(..)).
The text is returned as printed, including a final newline:
Run the command and return its exit status and output as data. A non-zero
exit code or a signal is not an error here: match on output.status, or
call Output.require_success.
Standard output and standard error are captured, and standard input is
Null, unless the command sets them. The result is returned once the
command has exited and all of its output has been read.
Report whether command can be found on the system as something runnable.
A bare name (like "git") is looked up across the PATH entries; a name
containing a path separator is checked as-is. On Windows the candidate
extensions come from %PATHEXT%.
On Unix this checks for an executable bit; a directory is not reported even
though it carries one, though a symbolic link to a directory is a rare
exception.
The program and its arguments, separated by spaces, for messages and logs.
An argument that is empty or contains a space or a quote is written as a
quoted, escaped string. The environment, the working directory and the
other settings are not included.
Customize command output for Str.inspect: the full configuration, with
the names of the environment variables it sets but never their values, and
the length of Bytes input but not its content.
Bytes(bytes): the given bytes, after which the input ends.
Pipe: a pipe written with [Child.write_bytes!] and ended with [Child.close_stdin!]. Only [spawn!] returns a Child, so with [exec!], [capture!] and [run!] it means Null.
Capture: kept in memory and returned in the Output.
Tee: captured and also forwarded to the parent's standard output. The child sees a pipe, not a terminal.
Pipe: queued as chunks for [Child.read!]. Only [spawn!] returns a Child, so with [exec!], [capture!] and [run!] it means Capture.
StderrMode : [Inherit, Null, Capture, Tee, Pipe, MergeWithStdout]
Where the child's standard error goes: the modes of StdoutMode, or
MergeWithStdout, which sends it into the same OS pipe as standard output.
That keeps the order in which the child wrote to the two streams, which two
separate streams cannot. The merged stream follows the standard output
mode and is reported as standard output.
Why a command could not be started or did not run to completion. A
non-zero exit code is not one of these: it is BadExitStatus, or the
status of an Output.
StartFailed(err, program): the program could not be started, for example StartFailed(NotFound, program) when it does not exist.
TimedOut(partial): the command reached the deadline set with timeout and was killed.
OutputLimitExceeded(partial): the command printed more than output_limit or pending_limit allows and was killed.
IOErr(err): an operating-system failure while the command ran. A [Child.read!] or [Child.write_bytes!] that waited for its whole Duration is IOErr(TimedOut).
The result of a command that ran to completion: how it ended and what it
printed. command is the program and arguments, as to_str renders them.
Output is empty for a stream that was not captured.
When the last reference to a child is released, a child that is still
running is killed and reaped. Use [Child.close!] to do that at a chosen
point. After close! every other operation returns Err(Closed).
Wait for the child to exit and for all of its output to be read, then
return its status and captured output. A piped standard input is
closed first, so exchange data with [write_bytes!] and [read!] before
waiting. Waiting again returns the same result.
Return the next chunk of Pipe output, from whichever stream has
one, waiting up to wait for it. The host picks the chunk size.
Duration.zero does not wait: it returns a chunk that is ready, and
otherwise times out. A wait that expires is
Err(CmdErr(IOErr(TimedOut))); the child keeps running and may be
read again. Once the child has exited and every chunk has been
returned, the result is Err(EndOfInput).
Write bytes to a piped standard input, waiting up to wait for the
child to accept all of them. Duration.zero makes one attempt that
does not wait.
A wait that expires is Err(CmdErr(IOErr(TimedOut))). Part of the
input may have been delivered by then, so writing all of it again can
duplicate bytes. Writing when standard input is not a pipe, or after
[close_stdin!], is Err(CmdErr(IOErr(BrokenPipe))).