Skip to main content

getoutput

Function getoutput 

Source
pub fn getoutput(cmd: &str, qt: i32) -> 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, then spacesplit(buf, allownull=false) per c:4865-4871.

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. getoutput — see implementation.