pub fn getoutput(cmd: &str, qt: i32) -> Option<Vec<String>>Expand description
Port of LinkList getoutput(char *cmd, int qt) from
Src/exec.c:4712-4791. Runs a command-substitution body in the
active executor, then routes the captured stdout through
readoutput(pipe, qt, NULL) semantics at c:4855-4872.
C return shape: LinkList of char*. Rust port returns
Vec<String> (same shape, owned).
qt matches C exactly:
- qt=1 (quoted,
"$(...)"): trim trailing newlines, return entire output as a single-element vec. C c:4858-4862: if output empty, returns a single Nularg sentinel so callers see “empty value” rather than “no value”. - qt=0 (unquoted,
$(...)): trim trailing newlines, thenspacesplit(buf, allownull=false)per c:4865-4871, andshtokenizeeach word whenGLOBSUBSTis set (c:4868-4869) so the substituted words glob downstream.
Both arms — $(< file) (c:4746) and $( cmd ) (c:4772) — go through
the same c:4858-4872 tail (inlined twice — see the cross-reference
notes at :619 and :3829), mirroring C where both go through readoutput.
Uses with_executor (panics on missing VM context), not
try_with_executor + unwrap_or_default(). C getoutput calls
execpline directly — there’s no “no shell” code path. The
silent-no-op pattern (return empty string when no executor) would
mask catastrophic state corruption as “command produced no output”,
which is the failure mode the subst.rs:496 warning block flags.
Port of getoutput() from Src/exec.c:4713 — C decl getoutput(char *cmd, int qt).
getoutput — see implementation.