Exec
Overview
Exec runs a shell-less command string split on whitespace (child_process.exec).
If you are coming from Node.js, the closest pattern is exec('ls -la').
Signature
go
func Exec(ctx context.Context, command string) ([]byte, error)Compare: Node.js · Standard Go · gox
js
exec('ls -la')go
cmd := exec.CommandContext(ctx, name, args...)
out, err := cmd.CombinedOutput()go
import "github.com/sahilkhaire/gox/exec"
exec.Exec(ctx, command)Example
go
import "github.com/sahilkhaire/gox/exec"
exec.Exec(ctx, command)Tips
Pass context.Context as the first argument so cancellation and deadlines propagate correctly.
Standard library alternative
Use the standard library directly:
go
cmd := exec.CommandContext(ctx, name, args...)
out, err := cmd.CombinedOutput()