#os/exec
Xu 0.16.0 API
导入方式: #os/exec
公开 API: 3 函数, 11 方法, 1 类型, 0 常量, 0 方法集
进程执行:参数数组、run/output/combined_output、start/wait 与标准输入输出管道。
struct Cmd
pub struct Cmd {
pub path string
pub args []string
pub dir string
pub ctx context.Context
pub has_ctx int
}
用途
承载 path、args、dir、ctx、has_ctx 等属性的结构体。
公开字段
path string- 文件系统路径
args []string- 可变实参
dir string- 目录
ctx context.Context- 字段(context.Context)
has_ctx int- 字段(int)
($&Cmd) set_dir
pub fn (c $&Cmd) set_dir(dir string)
用途
$&Cmd 上的操作:设置 dir。
参数
c $&Cmd- 本次调用使用的
Cmd 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
dir string- 目录(string)
返回值
不返回值。
command
pub fn command(name string, args <-> string) Cmd
用途
命令。
参数
name string- 名字(string)
args <-> string- 可变参数,类型 string,在函数体内是 []string
返回值
Cmd — 该类型的值
command_context
pub fn command_context(ctx context.Context, name string, args <-> string) Cmd
用途
命令上下文。
参数
ctx context.Context- ctx(context.Context)
name string- 名字(string)
args <-> string- 可变参数,类型 string,在函数体内是 []string
返回值
Cmd — 该类型的值
look_path
pub fn look_path(file string) string
用途
执行 look path 操作。失败时抛出错误,调用方需处理或继续传播。
参数
file string- file(string)
返回值
string — 结果字符串
(&Cmd) run_status
pub fn (c &Cmd) run_status() int
用途
&Cmd 上的操作:执行 run status 操作。失败时抛出错误,调用方需处理或继续传播。
参数
c &Cmd- 本次调用使用的
Cmd 实例;以只读借用传入,调用方仍持有实例。
返回值
int — 该类型的值
(&Cmd) run
pub fn (c &Cmd) run() int
用途
&Cmd 上的操作:运行。失败时抛出错误,调用方需处理或继续传播。
参数
c &Cmd- 本次调用使用的
Cmd 实例;以只读借用传入,调用方仍持有实例。
返回值
int — 该类型的值
(&Cmd) output
pub fn (c &Cmd) output() string
用途
&Cmd 上的操作:输出。失败时抛出错误,调用方需处理或继续传播。
参数
c &Cmd- 本次调用使用的
Cmd 实例;以只读借用传入,调用方仍持有实例。
返回值
string — 结果字符串
($&Cmd) close_unstarted_pipes
pub fn (c $&Cmd) close_unstarted_pipes()
用途
$&Cmd 上的操作:执行 close unstarted pipes 操作。
参数
c $&Cmd- 本次调用使用的
Cmd 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
返回值
不返回值。
($&Cmd) stdout_pipe
pub fn (c $&Cmd) stdout_pipe() os.File
用途
$&Cmd 上的操作:执行 stdout pipe 操作。失败时抛出错误,调用方需处理或继续传播。
参数
c $&Cmd- 本次调用使用的
Cmd 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
返回值
os.File — 该类型的值
($&Cmd) stderr_pipe
pub fn (c $&Cmd) stderr_pipe() os.File
用途
$&Cmd 上的操作:执行 stderr pipe 操作。失败时抛出错误,调用方需处理或继续传播。
参数
c $&Cmd- 本次调用使用的
Cmd 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
返回值
os.File — 该类型的值
($&Cmd) stdin_pipe
pub fn (c $&Cmd) stdin_pipe() os.File
用途
$&Cmd 上的操作:执行 stdin pipe 操作。失败时抛出错误,调用方需处理或继续传播。
参数
c $&Cmd- 本次调用使用的
Cmd 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
返回值
os.File — 该类型的值
($&Cmd) start
pub fn (c $&Cmd) start() int
用途
$&Cmd 上的操作:启动。失败时抛出错误,调用方需处理或继续传播。
参数
c $&Cmd- 本次调用使用的
Cmd 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
返回值
int — 该类型的值
($&Cmd) wait
pub fn (c $&Cmd) wait() int
用途
$&Cmd 上的操作:等待。失败时抛出错误,调用方需处理或继续传播。
参数
c $&Cmd- 本次调用使用的
Cmd 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
返回值
int — 该类型的值
(&Cmd) combined_output
pub fn (c &Cmd) combined_output() string
用途
&Cmd 上的操作:合并输出输出。失败时抛出错误,调用方需处理或继续传播。
参数
c &Cmd- 本次调用使用的
Cmd 实例;以只读借用传入,调用方仍持有实例。
返回值
string — 结果字符串