std.process 包

功能介绍

process 包主要提供 Process 进程操作接口,主要包括进程创建,标准流获取,进程等待,进程信息查询等。

本包提供多平台统一操控能力,目前支持 Linux 平台,macOS 平台,Windows 平台与 HarmonyOS 平台。

API 列表

函数

函数名功能
execute根据输入参数创建并运行一个子进程,等待该子进程运行完毕并返回子进程退出状态。
executeWithOutput根据输入参数创建并运行一个子进程,等待该子进程运行完毕并返回子进程退出状态、标准输出和标准错误。
findProcess根据输入进程 id 绑定一个进程实例。
launch根据输入参数创建并运行一个子进程,并返回一个子进程实例。

类名功能
CurrentProcess (deprecated)此类为当前进程类,继承 Process 类,提供对当前进程操作相关功能。
Process此类为进程类,提供进程操作相关功能。
SubProcess此类为子进程类,继承 Process 类,提供对子进程操作相关功能。

枚举

枚举名功能
ProcessRedirect用于在创建进程时设置子进程标准流的重定向模式。

异常类

异常类名功能
ProcessExceptionprocess 包的异常类。

兼容性说明

class Process

成员支持平台
current (deprecated)Linux Windows macOS HarmonyOS
pidLinux Windows macOS HarmonyOS
nameLinux Windows macOS HarmonyOS
commandLinux 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, Path, Map<String, String>, ProcessRedirect, ProcessRedirect, ProcessRedirect) (deprecated)Linux Windows macOS HarmonyOS
run(String, Array, Path, Map<String, String>, ProcessRedirect, ProcessRedirect, ProcessRedirect, Duration) (deprecated)Linux Windows macOS HarmonyOS
runOutput(String, Array, Path, Map<String, String>, ProcessRedirect, ProcessRedirect, ProcessRedirect) (deprecated)Linux Windows macOS HarmonyOS
terminate(Bool)Linux Windows macOS HarmonyOS

class CurrentProcss (deprecated)

注意

未来版本即将废弃,可在 std.env 中找到代替功能。

成员支持平台
argumentsLinux Windows macOS HarmonyOS
homeDirectoryLinux Windows macOS
tempDirectoryLinux Windows macOS
stdInLinux Windows macOS HarmonyOS
stdOutLinux Windows macOS HarmonyOS
stdErrLinux 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
stdInPipeLinux Windows macOS HarmonyOS
stdOut (deprecated)Linux Windows macOS HarmonyOS
stdOutPipeLinux Windows macOS HarmonyOS
stdErr (deprecated)Linux Windows macOS HarmonyOS
stdErrPipeLinux Windows macOS HarmonyOS
wait(Duration)Linux Windows macOS HarmonyOS
waitOutput()Linux Windows macOS HarmonyOS