executers

package
v0.0.0-...-955c50f Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2024 License: Apache-2.0 Imports: 17 Imported by: 11

Documentation

Overview

Package executers contains general purpose (shell) command executing objects.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateScriptFile

func CreateScriptFile(scriptPath string, commands []string) (err error)

CreateScriptFile creates a script containing the given commands.

func ExecuteCommand

func ExecuteCommand(
	context context.T,
	cancelFlag task.CancelFlag,
	workingDir string,
	stdoutWriter io.Writer,
	stderrWriter io.Writer,
	executionTimeout int,
	commandName string,
	commandArguments []string,
	envVars map[string]string,
) (exitCode int, err error)

ExecuteCommand executes the given commands using the given working directory. Standard output and standard error are sent to the given writers.

func QuotePsString

func QuotePsString(str string) (result string)

QuotePsString replaces the quote

func QuoteShString

func QuoteShString(str string) (result string)

QuoteShString replaces the quote

func StartCommand

func StartCommand(context context.T,
	cancelFlag task.CancelFlag,
	workingDir string,
	stdoutWriter io.Writer,
	stderrWriter io.Writer,
	commandName string,
	commandArguments []string,
) (process *os.Process, exitCode int, err error)

StartCommand starts the given commands using the given working directory. Standard output and standard error are sent to the given writers.

Types

type ShellCommandExecuter

type ShellCommandExecuter struct {
}

ShellCommandExecuter is specially added for testing purposes

func (ShellCommandExecuter) Execute

func (ShellCommandExecuter) Execute(
	context context.T,
	workingDir string,
	stdoutFilePath string,
	stderrFilePath string,
	cancelFlag task.CancelFlag,
	executionTimeout int,
	commandName string,
	commandArguments []string,
	envVars map[string]string,
) (stdout io.Reader, stderr io.Reader, exitCode int, errs []error)

Execute executes a list of shell commands in the given working directory. If no file path is provided for either stdout or stderr, output will be written to a byte buffer. Returns readers for the standard output and standard error streams, process exit code, and a set of errors. The errors need not be fatal - the output streams may still have data even though some errors are reported. For example, if the command got killed while executing, the streams will have whatever data was printed up to the kill point, and the errors will indicate that the process got terminated.

For files, the reader returned will not contain more than appconfig.MaxStdoutLength and appconfig.MaxStderrLength respectively so if the caller needs to process more output than that, it should open its own reader on the output files.

For byte buffer output, the reader will be a reader over the buffer, which will accumulate the entire output. Be careful not to use the byte buffer approach for extremely large output (or unknown output) because it could take up a large amount of memory.

func (ShellCommandExecuter) NewExecute

func (ShellCommandExecuter) NewExecute(
	context context.T,
	workingDir string,
	stdoutWriter io.Writer,
	stderrWriter io.Writer,
	cancelFlag task.CancelFlag,
	executionTimeout int,
	commandName string,
	commandArguments []string,
	envVars map[string]string,
) (exitCode int, err error)

NewExecute executes a list of shell commands in the given working directory and provides the stdout and stderr writers.

func (ShellCommandExecuter) StartExe

func (ShellCommandExecuter) StartExe(
	context context.T,
	workingDir string,
	stdoutWriter io.Writer,
	stderrWriter io.Writer,
	cancelFlag task.CancelFlag,
	commandName string,
	commandArguments []string,
) (process *os.Process, exitCode int, err error)

StartExe starts a list of shell commands in the given working directory. Returns process started, an exit code (0 if successfully launch, 1 if error launching process), and a set of errors. The errors need not be fatal - the output streams may still have data even though some errors are reported. For example, if the command got killed while executing, the streams will have whatever data was printed up to the kill point, and the errors will indicate that the process got terminated.

type T

type T interface {
	//TODO: Remove Execute and rename NewExecute to Execute.
	Execute(context.T, string, string, string, task.CancelFlag, int, string, []string, map[string]string) (io.Reader, io.Reader, int, []error)
	NewExecute(context.T, string, io.Writer, io.Writer, task.CancelFlag, int, string, []string, map[string]string) (int, error)
	StartExe(context.T, string, io.Writer, io.Writer, task.CancelFlag, string, []string) (*os.Process, int, error)
}

T is the interface type for ShellCommandExecuter.

Jump to

Keyboard shortcuts

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