Documentation
¶
Index ¶
Constants ¶
const ( ExecUseShell execShellFlag = true ExecNoShell execShellFlag = false )
const ( ExecIgnoreErrors execIgnoreErrorsFlag = true ExecNoIgnoreErrors execIgnoreErrorsFlag = false )
const ( ExecQuiet execQuietFlag = true ExecNoQuiet execQuietFlag = false )
Variables ¶
This section is empty.
Functions ¶
func Exec ¶
Exec returns a Command that runs an external program as a pipeline stage: the input stream is written to the program's stdin and its stdout becomes the output stream (exactly the role of a command in a shell pipe).
The program and its arguments are the positional string parameters:
Exec("tr", "a-z", "A-Z")
Flags (see opt.go and the alias package):
- ExecWorkingDir(dir): run in dir
- ExecEnvVar("K=V"): add an environment variable (repeatable)
- ExecShell(sh) / ExecUseShell: run the command line through a shell
- ExecQuiet: discard the program's stderr
- ExecIgnoreErrors: succeed even if the program exits non-zero
When no flag needs shell features the program is executed directly; otherwise it is run through a POSIX shell so the flags can take effect.
Note: a generic exec runs arbitrary binaries, which the framework otherwise discourages in favor of per-tool Subprocess wrappers. It is offered here as an explicit, opt-in escape hatch.
func Plan ¶
Plan resolves parameters into the concrete program and arguments Exec would run, without spawning anything. It is the dry-run / preview counterpart of Exec: a caller can log or inspect the exact command line first. It returns ErrNoCommand when no program is named.
When no flag needs shell features the program and its arguments are returned directly; otherwise the program is wrapped in a POSIX shell invocation ("sh -c <command line>") so the flags take effect.
Types ¶
type Error ¶
type Error string
Error is the sentinel error type for this package. Every error the package can emit is a constant of this type, so callers match with errors.Is.
const ErrNoCommand Error = "exec: no command specified"
ErrNoCommand is returned by Exec when no program is given to run.
type ExecEnvVar ¶
type ExecEnvVar string
ExecEnvVar adds one KEY=VALUE environment variable (repeatable).
type ExecShell ¶
type ExecShell string
ExecShell names the shell interpreter to route the command through.
type ExecWorkingDir ¶
type ExecWorkingDir string
ExecWorkingDir runs the command in the named directory.