std.os Package

Function Description

The OS package provides capabilities such as obtaining or operating on information about the current process (such as process parameters, environment variables, and directory information), registering callback functions, and exiting the current process.

Currently, the OS package is supported on the Linux, macOS, Windows, and HarmonyOS platforms.

API List

Function

NameDescriptionSupported on
currentDir()Obtains the current working directory.Linux, Windows, macOS, and HarmonyOS
envVars()Obtains all environment variables.Linux, Windows, macOS, and HarmonyOS
getArgs()Obtains the command line parameter list, for example, running a.out ab cd ef in the command line, where a.out is the program name. The returned list contains three elements: ab, cd, and ef.Linux, Windows, macOS, and HarmonyOS
getEnv(String)Obtains the value of a specified environment variable.Linux, Windows, macOS, and HarmonyOS
homeDir()Obtains the home directory.Linux, Windows, and macOS
processorCount()Obtains the number of processors.Linux, Windows, macOS, and HarmonyOS
removeEnv(String)Removes an environment variable by specifying its name.Linux, Windows, macOS, and HarmonyOS
setEnv(String, String)Sets a pair of environment variables.Linux, Windows, macOS, and HarmonyOS
tempDir()Obtains the temporary directory.Linux, Windows, macOS, and HarmonyOS