shell

package
v3.3.7 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2026 License: BSD-3-Clause Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Command added in v3.3.7

func Command(ctx context.Context, name string, args ...string) *exec.Cmd

func Exec

func Exec(ctx context.Context, shell string) (string, error)

Exec 执行已拼好的 shell 命令

func ExecWithLog

func ExecWithLog(ctx context.Context, shell string, logFile string) error

func ExecWithLogAppend added in v3.3.6

func ExecWithLogAppend(ctx context.Context, shell string, logFile string) error

func ExecWithOutput added in v3.3.6

func ExecWithOutput(ctx context.Context, shell string) error

ExecWithOutput 执行已拼好的 shell 命令并输出到终端

func ExecWithPipe added in v3.3.6

func ExecWithPipe(ctx context.Context, shell string) (io.ReadCloser, error)

ExecWithPipe stdout 与 stderr 合并成流,命令失败时读端收到错误

func ExecWithStdinProgress added in v3.3.1

func ExecWithStdinProgress(
	ctx context.Context,
	name string, args, env []string,
	stdin io.Reader, total int64,
	interval time.Duration,
	progress func(written, total int64, rate float64),
) (string, error)

ExecWithStdinProgress 以外部命令消费 stdin,同时按周期通过 progress 回调输出进度

func Execf

func Execf(ctx context.Context, format string, args ...any) (string, error)

Execf 按格式串拼出 shell 命令后执行

func ExecfAsync

func ExecfAsync(ctx context.Context, format string, args ...any) error

func ExecfWithDir

func ExecfWithDir(ctx context.Context, dir, format string, args ...any) (string, error)

func ExecfWithEnv added in v3.3.2

func ExecfWithEnv(ctx context.Context, env []string, format string, args ...any) (string, error)

func ExecfWithTimeout

func ExecfWithTimeout(ctx context.Context, timeout time.Duration, format string, args ...any) (string, error)

func Quote added in v3.3.7

func Quote(s string) string

Types

type MessagePing

type MessagePing struct {
	Ping bool `json:"ping"`
}

MessagePing ping 消息

type MessageResize

type MessageResize struct {
	Resize  bool `json:"resize"`
	Columns uint `json:"columns"`
	Rows    uint `json:"rows"`
}

MessageResize 终端大小调整消息

type Turn

type Turn struct {
	// contains filtered or unexported fields
}

Turn PTY 终端

func NewPTYTurn

func NewPTYTurn(ctx context.Context, ws *websocket.Conn, shell string) (*Turn, error)

NewPTYTurn 使用 PTY 执行命令,返回 Turn 用于流式读取输出 调用方需要负责调用 Close() 和 Wait()

func (*Turn) Close

func (t *Turn) Close()

Close 关闭 PTY 并终止子进程

func (*Turn) Handle

func (t *Turn) Handle(ctx context.Context) error

Handle 从 WebSocket 读取输入写入 PTY

func (*Turn) Pipe

func (t *Turn) Pipe(ctx context.Context) error

Pipe 从 PTY 读取输出写入 WebSocket

func (*Turn) Resize

func (t *Turn) Resize(rows, cols uint16) error

Resize 调整 PTY 窗口大小

func (*Turn) Wait

func (t *Turn) Wait()

Wait 等待命令完成

func (*Turn) Write

func (t *Turn) Write(data []byte) (int, error)

Write 写入 PTY 输入

Jump to

Keyboard shortcuts

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