MCPcopy Index your code
hub / github.com/alexellis/go-execute

github.com/alexellis/go-execute @v2.2.1

Chat with this repo
repository ↗ · DeepWiki ↗ · release v2.2.1 ↗ · + Follow
17 symbols 46 edges 3 files 0 documented · 0% 3 cross-repo links
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

go-execute

A wrapper for Go's command execution packages.

go get github.com/alexellis/go-execute/v2

Docs

See docs at pkg.go.dev: github.com/alexellis/go-execute

go-execute users

Used by dozens of projects as identified by GitHub, notably:

Community examples:

Feel free to add a link to your own projects in a PR.

Main options

  • DisableStdioBuffer - Discard Stdio, rather than buffering into memory
  • StreamStdio - Stream stderr and stdout to the console, useful for debugging and testing
  • Shell - Use bash as a shell to execute the command, rather than exec a binary directly
  • StdOutWriter - an additional writer for stdout, useful for mutating or filtering the output
  • StdErrWriter - an additional writer for stderr, useful for mutating or filtering the output
  • PrintCommand - print the command to stdout before executing it

Example of exec without streaming to STDIO

This example captures the values from stdout and stderr without relaying to the console. This means the values can be inspected and used for automation.

package main

import (
    "fmt"

    execute "github.com/alexellis/go-execute/v2"
    "context"
)

func main() {
    cmd := execute.ExecTask{
        Command:     "docker",
        Args:        []string{"version"},
        StreamStdio: false,
    }

    res, err := cmd.Execute(context.Background())
    if err != nil {
        panic(err)
    }

    if res.ExitCode != 0 {
        panic("Non-zero exit code: " + res.Stderr)
    }

    fmt.Printf("stdout: %s, stderr: %s, exit-code: %d\n", res.Stdout, res.Stderr, res.ExitCode)
}

Example with "shell" and exit-code 0

package main

import (
    "fmt"

    execute "github.com/alexellis/go-execute/v2"
    "context"
)

func main() {
    ls := execute.ExecTask{
        Command: "ls",
        Args:    []string{"-l"},
        Shell:   true,
    }
    res, err := ls.Execute(context.Background())
    if err != nil {
        panic(err)
    }

    fmt.Printf("stdout: %q, stderr: %q, exit-code: %d\n", res.Stdout, res.Stderr, res.ExitCode)
}

Example with "shell" and exit-code 1

package main

import (
    "fmt"

    "context"
    execute "github.com/alexellis/go-execute/v2"
)

func main() {
    ls := execute.ExecTask{
        Command: "exit 1",
        Shell:   true,
    }
    res, err := ls.Execute(context.Background())
    if err != nil {
        panic(err)
    }

    fmt.Printf("stdout: %q, stderr: %q, exit-code: %d\n", res.Stdout, res.Stderr, res.ExitCode)
}

Contributing

Commits must be signed off with git commit -s

License: MIT

Core symbols most depended-on inside this repo

Shape

Function 14
Struct 2
Method 1

Languages

Go100%

Modules by API surface

exec_test.go13 symbols
exec.go3 symbols
exec_unix_test.go1 symbols

Used by 3 indexed graphs manifest dependencies, hub-wide

For agents

$ claude mcp add go-execute \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page