executil

package
v0.85.0-pre.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 15, 2026 License: BSD-3-Clause Imports: 7 Imported by: 0

README

kit/executil

github.com/vormadev/vorma/kit/executil

Helpers for running subprocesses with stdout/stderr wired to the current process.

Import

import "github.com/vormadev/vorma/kit/executil"

Prefer RunCmd/MakeCmdRunner when possible:

if err := executil.RunCmd("go", "test", "./..."); err != nil {
	return err
}

Reusable runner:

build := executil.MakeCmdRunner("go", "build", "./cmd/server")
if err := build(); err != nil {
	return err
}

Shell Usage

// Unix: sh -c
// Windows: cmd /C
if err := executil.RunShell("echo hello"); err != nil {
	return err
}

Security note:

  • RunShell executes via a shell and is vulnerable to shell injection if untrusted input is interpolated.
  • Use RunCmd with explicit argument separation for user-controlled values.

Executable Directory

dir, err := executil.GetExecutableDir()

Behavior Notes

  • MakeCmdRunner returns an error when called with no command.
  • RunCmd and RunShell return command execution errors directly.
  • Output streams are attached to os.Stdout and os.Stderr.

API Reference

  • func MakeCmdRunner(commands ...string) func() error
  • func RunCmd(commands ...string) error
  • func RunShell(command string) error
  • func GetExecutableDir() (string, error)

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrCommandExecutionTimedOut = errors.New("command execution timed out")
	ErrCommandExecutionCanceled = errors.New("command execution canceled")
)

Functions

func GetExecutableDir

func GetExecutableDir() (string, error)

func MakeCmdRunner

func MakeCmdRunner(commands ...string) func() error

func RunCmd

func RunCmd(commands ...string) error

func RunCmdCapture

func RunCmdCapture(commands ...string) (string, error)

func RunShell

func RunShell(command string) error

func RunShellWithContext

func RunShellWithContext(
	commandExecutionContext context.Context,
	command string,
) error

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL