Documentation
¶
Overview ¶
Package command runs external programs.
Every function except RunShellAsync executes the binary directly through os/exec with an already-tokenized argv — there is NO shell in between. That is the point of this package, not an implementation detail: arguments are never re-parsed, so globbing, quoting, $VAR expansion, `;`, `|` and `&&` have no meaning and command injection is impossible.
command.Run("git", "commit", "-m", userInput) // safe: userInput is one argv entry
If you genuinely need a shell, RunShellAsync says so in its name. Never build a command line by concatenating untrusted input into it.
Zero dependencies.
Index ¶
- Variables
- func Run(name string, args ...string) (string, error)
- func RunInDir(dir, name string, args ...string) (string, error)
- func RunShellAsync(commandLine string) error
- func RunWithRetry(dir, name string, args []string, attempts int, delay time.Duration) (string, error)
- func RunWithStdin(input, name string, args ...string) (string, error)
Constants ¶
This section is empty.
Variables ¶
var Exec = exec.Command
Exec builds the *exec.Cmd every function here runs. Tests replace it to intercept execution; production code never touches it.
Functions ¶
func Run ¶ added in v0.0.2
Run executes name with args and returns its combined output, trimmed. A non-zero exit is an error whose message carries the command and its output.
func RunShellAsync ¶ added in v0.0.2
RunShellAsync starts commandLine in the platform shell (sh -c, or cmd.exe /C on Windows) and returns immediately without waiting for it to finish.
This is the ONLY function here that opens a shell, so commandLine IS parsed: never build it from untrusted input.
Types ¶
This section is empty.