shell

package
v0.9.4 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CaptureShellSnippet

func CaptureShellSnippet(snippet string, env map[string]string) (string, int, error)

Execute a shell snippet and get the result, return code and sys error

func Exec

func Exec(command string, args []string, env map[string]string, ctlIo *ExecControl) *exec.Cmd

Exec is an asynchronous wrapper for the exec command.

// run a shell snippet synchronously to list a folder
//   nil env - no extra env variables set
//   nil ctl - use Stdout & Stderr
exe := shell.Exec("/usr/bin/bash", []string{"-c", "ls -al"}, nil, nil)
fmt.Printf("Script has returned with exit code %v", exe.ProcessState.ExitCode())

The returned exec.Cmd can be used to wait for the command to finish.

func ExecAsync

func ExecAsync(command string, args []string, env map[string]string, ctl *ExecControl) *exec.Cmd

Execute a shell command asynchronously, restreaming Stdin & StdOut.

To get results from the shell command, use struct ExecControl. If ctl is nil then Stdout & Stderr will receive the output and the Status will be discarded.

// run a shell snippet Asynchronously to list a folder
//   nil env - no extra env variables set
//   nil ctl - use Stdout & Stderr
exe := shell.Exec("/usr/bin/bash", []string{"-c", "ls -al"}, nil, nil)
fmt.Printf("The script is still running...")

The returned exec.Cmd can be used to wait for the command to finish.

func GetShellPath

func GetShellPath() string

GitCmd represents the base core

func ShellSnippet

func ShellSnippet(snippet string) string

Execute a shell snippet, print & return result On error (exitStatus>0), and os.Exit(exitStatus)

func StreamShellSnippet

func StreamShellSnippet(snippet string, env map[string]string) *exec.Cmd

Execute a shell snippet and stream the result, stdError & return status

Types

type ExecControl

type ExecControl struct {
	StdOutWriter io.Writer
	StdErrWriter io.Writer
	ProcessState chan int
}

ExecControl is a simple structure to control the output of the ExecAsync command. See Exec for details of how to wrap the Async command to make it synchronous.

ExecAsync will send the ExitCode on the channel when the command terminates. No other comms occur on the channel. Note that the ExitCode will be -1 if the process is running or was terminated by a signal (forced termination)

Jump to

Keyboard shortcuts

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