sdexec

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package sdexec 运行外部程序

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrTimeout = sderr.New("timeout")
)
View Source
var (
	NoEnv = Env{}
)

Functions

This section is empty.

Types

type Cmd

type Cmd struct {
	Name string
	Args []string
	Env
	Timeout time.Duration
}

func Parse

func Parse(line string) (*Cmd, error)

func Parsef

func Parsef(format string, a ...any) (*Cmd, error)

func (*Cmd) AddVars

func (cmd *Cmd) AddVars(vars map[string]string) *Cmd

func (*Cmd) New

func (cmd *Cmd) New() *exec.Cmd

func (*Cmd) Run

func (cmd *Cmd) Run() error

func (*Cmd) RunConsole

func (cmd *Cmd) RunConsole() error

func (*Cmd) RunOutput

func (cmd *Cmd) RunOutput(combine bool) ([]byte, error)

func (*Cmd) RunOutputString

func (cmd *Cmd) RunOutputString(combine bool) (string, error)

func (*Cmd) RunResult

func (cmd *Cmd) RunResult() *Result

func (*Cmd) SetDir

func (cmd *Cmd) SetDir(wd string) *Cmd

func (*Cmd) SetTimeout

func (cmd *Cmd) SetTimeout(timeout time.Duration) *Cmd

func (*Cmd) SetVar

func (cmd *Cmd) SetVar(name, val string) *Cmd

func (*Cmd) SetVars

func (cmd *Cmd) SetVars(vars map[string]string) *Cmd

type Env

type Env struct {
	Dir  string
	Vars map[string]string
}

func (Env) Run

func (p Env) Run(line string) error

func (Env) RunConsole

func (p Env) RunConsole(line string) error

func (Env) RunOutput

func (p Env) RunOutput(line string, combine bool) ([]byte, error)

func (Env) RunOutputString

func (p Env) RunOutputString(line string, combine bool) (string, error)

func (Env) RunResult

func (p Env) RunResult(line string) (*Result, error)

type Result

type Result struct {
	Name   string            // 程序名称
	Args   []string          // 程序参数
	Dir    string            // 程序的运行目录
	Envs   map[string]string // 程序的环境变量
	Stdout []byte            // 标准输出
	Stderr []byte            // 错误输出
	Err    error             // 错误信息
	Usage  Rusage            // 进程概况
}

func (*Result) Cli

func (r *Result) Cli() string

func (*Result) ExitCode

func (r *Result) ExitCode() int

func (*Result) HasErr

func (r *Result) HasErr() bool

func (*Result) StderrLines

func (r *Result) StderrLines() []string

func (*Result) StderrString

func (r *Result) StderrString() string

func (*Result) StdoutLines

func (r *Result) StdoutLines() []string

func (*Result) StdoutString

func (r *Result) StdoutString() string

type Rusage

type Rusage syscall.Rusage

Jump to

Keyboard shortcuts

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