Skip to content
Node: child_processgithub.com/sahilkhaire/gox/exec

Cmd

Overview

Cmd wraps os/exec.Cmd with context cancellation.

Part of the exec package — Node.js analog: child_process.

Cmd is a type exported by gox. Methods on this type are documented separately.

Signature

go
type Cmd struct {
	// contains filtered or unexported fields
}

Compare: Node.js · Standard Go · gox

js
// Typical child_process pattern in Node.js
go
cmd := exec.CommandContext(ctx, name, args...)
out, err := cmd.CombinedOutput()
go
import "github.com/sahilkhaire/gox/exec"

cmd := exec.Command(ctx, "git", "status")
out, err := cmd.Output()

Example

go
import "github.com/sahilkhaire/gox/exec"

cmd := exec.Command(ctx, "git", "status")
out, err := cmd.Output()

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()

Back to exec package overview

MIT Licensed · Built for Node.js developers moving to Go