Struct std::process::ExitStatus1.0.0[][src]

pub struct ExitStatus(_);
Expand description

描述进程终止后的结果。

struct 用于表示子进程的退出状态或其他终止。 子进程是通过 Command 结构体创建的,其退出状态通过 status 方法或 Child 进程的 wait 方法公开。

ExitStatus 表示进程的每一种可能的配置。在 Unix 上,这是等待状态。 不是 仅仅是 exit 状态(传递给 exit 的值)。

为了正确报告失败进程的错误,请使用 Display 的实现打印 ExitStatusExitStatusError 的值。

Implementations

🔬 This is a nightly-only experimental API. (exit_status_error #84908)

终止成功了吗? 返回 Result

Examples
#![feature(exit_status_error)]
use std::process::Command;

let status = Command::new("ls")
                     .arg("/dev/nonexistent")
                     .status()
                     .expect("ls could not be executed");

println!("ls: {}", status);
status.exit_ok().expect_err("/dev/nonexistent could be listed!");
Run

终止成功了吗? 信号终止不被视为成功,并且成功被定义为零退出状态。

Examples
use std::process::Command;

let status = Command::new("mkdir")
                     .arg("projects")
                     .status()
                     .expect("failed to execute mkdir");

if status.success() {
    println!("'projects/' directory created");
} else {
    println!("failed to create 'projects/' directory: {}", status);
}
Run

返回进程的退出代码 (如果有)。

用 Unix 的术语来说,返回值是退出状态:如果进程通过调用 exit 完成,则传递给 exit 的值。 请注意,在 Unix 上,退出状态被截断为 8 位,并且不是来自程序调用到 exit 的值可能是由运行时系统发明的 (通常,例如,255、254、127 或 126)。

在 Unix 上,如果进程被信号终止,它将返回 NoneExitStatusExt 是 trait 的扩展,用于从 ExitStatus 中提取任何此类信号和其他细节。

Examples
use std::process::Command;

let status = Command::new("mkdir")
                     .arg("projects")
                     .status()
                     .expect("failed to execute mkdir");

match status.code() {
    Some(code) => println!("Exited with status code: {}", code),
    None       => println!("Process terminated by signal")
}
Run

Trait Implementations

返回值的副本。 Read more

source 执行复制分配。 Read more

使用给定的格式化程序格式化该值。 Read more

使用给定的格式化程序格式化该值。 Read more

wait 的原始底层整数状态值创建一个新的 ExitStatusExitStatusError Read more

如果进程被一个信号终止,则返回该信号。 Read more

如果进程被一个信号终止,说明它是否丢弃了核心。

如果该进程被信号停止,则返回该信号。 Read more

进程是否从停止状态继续。 Read more

返回底层的原始 wait 状态。 Read more

根据进程的原始底层 u32 返回值创建新的 ExitStatusRead more

执行转换。

此方法测试 selfother 值是否相等,并由 == 使用。 Read more

此方法测试 !=

Auto Trait Implementations

Blanket Implementations

获取 selfTypeIdRead more

从拥有的值中一成不变地借用。 Read more

从拥有的值中借用。 Read more

执行转换。

执行转换。

获得所有权后的结果类型。

从借用的数据创建拥有的数据,通常是通过克隆。 Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into #41263)

使用借来的数据来替换拥有的数据,通常是通过克隆。 Read more

将给定值转换为 StringRead more

发生转换错误时返回的类型。

执行转换。

发生转换错误时返回的类型。

执行转换。