shell

package
v3.1.1 Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2026 License: BSD-3-Clause Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Exec

func Exec(shell string) (string, error)

Exec 执行 shell 命令

func ExecWithLog

func ExecWithLog(shell string, logFile string) error

ExecWithLog 执行 shell 命令并将输出写入指定的日志文件

func Execf

func Execf(shell string, args ...any) (string, error)

Execf 安全执行 shell 命令

func ExecfAsync

func ExecfAsync(shell string, args ...any) error

ExecfAsync 异步执行 shell 命令

func ExecfWithDir

func ExecfWithDir(dir, shell string, args ...any) (string, error)

ExecfWithDir 在指定目录下执行 shell 命令

func ExecfWithOutput

func ExecfWithOutput(shell string, args ...any) error

ExecfWithOutput 执行 shell 命令并输出到终端

func ExecfWithPipe

func ExecfWithPipe(ctx context.Context, shell string, args ...any) (io.ReadCloser, error)

ExecfWithPipe 执行 shell 命令并返回管道

func ExecfWithTTY

func ExecfWithTTY(shell string, args ...any) (string, error)

ExecfWithTTY 在伪终端下执行 shell 命令

func ExecfWithTimeout

func ExecfWithTimeout(timeout time.Duration, shell string, args ...any) (string, error)

ExecfWithTimeout 执行 shell 命令并设置超时时间

func IsPTYError

func IsPTYError(err error) error

IsPTYError Linux kernel return EIO when attempting to read from a master pseudo terminal which no longer has an open slave. So ignore error here. See https://github.com/creack/pty/issues/21

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, args ...any) (*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