Documentation
¶
Index ¶
- func CaptureShellSnippet(snippet string, env map[string]string) (string, int, error)
- func Exec(command string, args []string, env map[string]string, ctlIo *ExecControl) *exec.Cmd
- func ExecAsync(command string, args []string, env map[string]string, ctl *ExecControl) *exec.Cmd
- func GetShellPath() string
- func ShellSnippet(snippet string) string
- func StreamShellSnippet(snippet string, env map[string]string) *exec.Cmd
- type ExecControl
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CaptureShellSnippet ¶
Execute a shell snippet and get the result, return code and sys error
func Exec ¶
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 ¶
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 ShellSnippet ¶
Execute a shell snippet, print & return result On error (exitStatus>0), and os.Exit(exitStatus)
Types ¶
type ExecControl ¶
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)