std.process
功能介绍
process 包主要提供 Process 进程操作接口,主要包括进程创建,标准流获取,进程等待,进程信息查询等。
本包提供多平台统一操控能力,目前支持 Linux 平台,macOS 平台,Windows 平台与 HarmonyOS 平台。
API 列表
函数
| 函数名 | 功能 |
|---|---|
| execute | 根据输入参数创建并运行一个子进程,等待该子进程运行完毕并返回子进程退出状态。 |
| executeWithOutput | 根据输入参数创建并运行一个子进程,等待该子进程运行完毕并返回子进程退出状态、标准输出和标准错误。 |
| findProcess | 根据输入进程 id 绑定一个进程实例。 |
| launch | 根据输入参数创建并运行一个子进程,并返回一个子进程实例。 |
类
| 类名 | 功能 |
|---|---|
| CurrentProcess (deprecated) | 此类为当前进程类,继承 Process 类,提供对当前进程操作相关功能。 |
| Process | 此类为进程类,提供进程操作相关功能。 |
| SubProcess | 此类为子进程类,继承 Process 类,提供对子进程操作相关功能。 |
枚举
| 枚举名 | 功能 |
|---|---|
| ProcessRedirect | 用于在创建进程时设置子进程标准流的重定向模式。 |
异常类
| 异常类名 | 功能 |
|---|---|
| ProcessException | process 包的异常类。 |
兼容性说明
class Process
| 成员 | 支持平台 |
|---|---|
| current (deprecated) | Linux Windows macOS HarmonyOS |
| pid | Linux Windows macOS HarmonyOS |
| name | Linux Windows macOS HarmonyOS |
| command | Linux Windows macOS HarmonyOS |
| arguments (deprecated) | Linux macOS HarmonyOS |
| commandLine (deprecated) | Linux macOS HarmonyOS |
| environment (deprecated) | Linux HarmonyOS |
| workingDirectory (deprecated) | Linux macOS HarmonyOS |
| of(Int64) (deprecated) | Linux Windows macOS HarmonyOS |
| start(String, Array<String>, Path, Map<String, String>, ProcessRedirect, ProcessRedirect, ProcessRedirect) (deprecated) | Linux Windows macOS HarmonyOS |
| run(String, Array<String>, Path, Map<String, String>, ProcessRedirect, ProcessRedirect, ProcessRedirect, Duration) (deprecated) | Linux Windows macOS HarmonyOS |
| runOutput(String, Array<String>, Path, Map<String, String>, ProcessRedirect, ProcessRedirect, ProcessRedirect) (deprecated) | Linux Windows macOS HarmonyOS |
| terminate(Bool) | Linux Windows macOS HarmonyOS |
class CurrentProcss (deprecated)
注意:
未来版本即将废弃,可在 std.env 中找到代替功能。
| 成员 | 支持平台 |
|---|---|
| arguments | Linux Windows macOS HarmonyOS |
| homeDirectory | Linux Windows macOS |
| tempDirectory | Linux Windows macOS |
| stdIn | Linux Windows macOS HarmonyOS |
| stdOut | Linux Windows macOS HarmonyOS |
| stdErr | Linux Windows macOS HarmonyOS |
| atExit(() -> Unit) | Linux Windows macOS HarmonyOS |
| exit(Int64) | Linux Windows macOS HarmonyOS |
| getEnv(String) | Linux Windows macOS HarmonyOS |
| removeEnv(String) | Linux Windows macOS HarmonyOS |
| setEnv(String, String) | Linux Windows macOS HarmonyOS |
class SubProcess
| 成员 | 支持平台 |
|---|---|
| stdIn (deprecated) | Linux Windows macOS HarmonyOS |
| stdInPipe | Linux Windows macOS HarmonyOS |
| stdOut (deprecated) | Linux Windows macOS HarmonyOS |
| stdOutPipe | Linux Windows macOS HarmonyOS |
| stdErr (deprecated) | Linux Windows macOS HarmonyOS |
| stdErrPipe | Linux Windows macOS HarmonyOS |
| wait(Duration) | Linux Windows macOS HarmonyOS |
| waitOutput() | Linux Windows macOS HarmonyOS |