Documentation
¶
Overview ¶
Package subprocess provides support for standard output/error pipe data & exit status codes with new spawned system processes
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Response ¶
Response is a struct that is returned from the public functions in the subprocess package. It contains the following fields:
Response.StdOut - (string) standard output stream cast to a string Response.StdErr - (string) standard error stream cast to a string Response.ExitCode - (int) executable exit status code as an integer
func Run ¶
Run is a public function that executes a system command and returns the standard output stream, standard error stream, and exit status code data in a returned subprocess.Response struct. Run takes the following parameters:
executable (string) - the system executable for the command call args (...string) - one or more executable arguments as comma delimited parameters
Example:
func main() {
response := Run("go", "--help")
fmt.Printf("%s\n", response.StdOut)
fmt.Printf("%s\n", response.StdErr)
fmt.Printf("%d\n", response.ExitCode)
}
func RunShell ¶ added in v0.2.0
RunShell is a public function that executes a system command with a shell and returns the standard output stream, standard error stream, and exit status code data in a returned subprocess.Response struct. RunShell takes the following parameters:
shell (string) - path to shell, optional. Defaults = /bin/sh on Linux, macOS; bash on Windows shellflag (string) - flag to execute system executable from a shell executable. Default = `-c` on all platforms command (...string) - one or more executable arguments as comma delimited parameters
Example:
func main() {
response := RunShell("", "", "ls", "-l")
fmt.Printf("%s\n", response.StdOut)
fmt.Printf("%s\n", response.StdErr)
fmt.Printf("%d\n", response.ExitCode)
response2 := RunShell("/usr/local/bin/zsh", "-c", "ls", "-l")
fmt.Printf("%s\n", response.StdOut)
fmt.Printf("%s\n", response.StdErr)
fmt.Printf("%d\n", response.ExitCode)
}