cmd_util

package
v0.0.0-...-d881874 Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2023 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// KilledExitCode is a special exit code value used by the "os/exec" package
	// when a process is killed.
	KilledExitCode = -1
	// NoExitCode indicates a missing exit code value, usually because the process
	// never started, or its actual exit code could not be determined because of an
	// error.
	NoExitCode = -2
)

Variables

This section is empty.

Functions

func ChildPids

func ChildPids(pid int) ([]int, error)

func ExitCode

func ExitCode(ctx context.Context, cmd *exec.Cmd, err error) (int, error)

func KillProcessTree

func KillProcessTree(pid int) error

func RetryIfTextFileBusy

func RetryIfTextFileBusy(fn func() error) error

func RunWithProcessTreeCleanup

func RunWithProcessTreeCleanup(ctx context.Context, cmd *exec.Cmd) error

Types

type Command

type Command struct {
	Content     string
	Env         []string // Each entry is of the form "key=value".
	Use_console bool
}

type CommandResult

type CommandResult struct {
	// 只有在命令无法启动,或者已经启动但没有完成的情况下,才会弹出错误信息。
	// 启动了但没有完成。
	//
	// 特别是,如果该命令运行并返回一个非零的退出代码(比如1)。
	// 这被认为是一个成功的执行,这个错误将不会被填入。
	//
	// 在某些情况下,该命令可能由于与命令本身无关的问题而未能启动。
	// 与命令本身无关。例如,运行器可能在一个
	// 但未能创建沙盒。在这种情况下,这里的
	// 这里的Error字段应填入一个gRPC错误代码,说明为什么该
	// 而ExitCode字段应该包含沙盒进程的退出代码。
	// 而ExitCode字段应该包含来自沙盒进程的退出代码,而不是命令本身。
	//
	// 如果对 "exec.Cmd#Run "的调用返回-1,意味着该命令被杀死或者
	// 如果对`exec.Cmd#Run'的调用返回-1,意味着命令被杀死或从未退出,那么这个字段应填入一个gRPC错误代码,说明其
	// 这个字段应该填入一个gRPC错误代码,说明原因,比如DEADLINE_EXCEEDED(如果命令超时),UNAVAILABLE(如果
	// 有一个可以重试的瞬时错误),或RESOURCE_EXHAUSTED(如果该
	// 命令在执行过程中耗尽了内存)。
	Error error

	// Stdout from the command. This may contain data even if there was an Error.
	Stdout []byte
	// Stderr from the command. This may contain data even if there was an Error.
	Stderr []byte

	// ExitCode is one of the following:
	// * The exit code returned by the executed command
	// * -1 if the process was killed or did not exit
	// * -2 (NoExitCode) if the exit code could not be determined because it returned
	//   an error other than exec.ExitError. This case typically means it failed to start.
	ExitCode int
}

func Run

func Run(ctx context.Context, command *Command, workDir string, stdio *Stdio) *CommandResult

type Stdio

type Stdio struct {
	// Stdin is an optional stdin source for the executed process.
	Stdin io.Reader
	// Stdout is an optional stdout sink for the executed process.
	Stdout io.Writer
	// Stderr is an optional stderr sink for the executed process.
	Stderr io.Writer
}

Jump to

Keyboard shortcuts

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