Run (exec.go)

tokless · infra

Resolves executable binaries, spawns processes, manages paths, handles health checks for command execution utility in Go.

// Source: https://github.com/HoangP8/tokless | License: MIT | Copyright 2026 HoangP8
// Provided via justclaw.it.com; keep this notice with the code.
package util

import (
	"bytes"
	"context"
	"os"
	"os/exec"
	"path/filepath"
	"strings"
)

// ExecResult mirrors the TS { code, stdout, stderr } shape.
type ExecResult struct {
	Code   int
	Stdout string
	Stderr string
}

// RunOptions controls stdio handling for Run.
type RunOptions struct {
	Capture bool
	Quiet   bool
	Cwd     string
	Env     []string
	Ctx     context.Context
}

// Run executes a command; Capture pipes stdio, Quiet discards it, else inherit.
func Run(cmd string, args []string, opts RunOptions) ExecResult {
	c := exec.Command(cmd, args...)
	if opts.Ctx != nil {
		prepareCommandForTreeKill(c)
	}
	if opts.Cwd != "" {
		c.Dir 

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search 40K more like it.

Get a free API key