std.env
Description
The env package provides information and functionalities related to the current process, including environment variables, command line arguments, standard streams, and exit programs. It also provides methods for interaction with standard input, standard output, and standard error streams.
This package provides unified control capabilities for multiple platforms, including Linux, macOS, Windows, and HarmonyOS.
This package provides getStdErr(), getStdIn(), and getStdOut() to obtain the three types of standard streams.
- ConsoleReader encapsulates the functionalities related to standard input streams. You can use related
readmethods to read data from standard input streams. - ConsoleWriter encapsulates functionalities related to standard output and standard error streams. ConsoleWriter encapsulates a series of
writemethods and provides the capability of writing data to standard output and standard error streams.
Standard input (stdin), standard output (stdout), and standard error (stderr) streams are three types of common streams in computer operating systems.
A standard input stream indicates that a program obtains input data from a user, which is usually a keyboard input. A standard output stream indicates that a program outputs results to a user, which is usually a screen output. A standard error stream indicates that a program outputs error information when an error occurs, which is usually a screen output.
On Unix or Linux, standard input, standard output, and standard error streams correspond to file descriptors 0, 1, and 2, respectively. Programs can use these file descriptors to read and write data. For example, redirection symbols can be used to redirect a standard output stream to a file, or to redirect a standard error output stream to a standard input stream of another program.
API List
Classes
| Name | Description |
|---|---|
| ConsoleReader | Provides functionalities of reading characters or strings from standard input streams. |
| ConsoleWriter | Provides functionalities of writing characters or strings to standard output or standard error streams. |
Functions
| Function | Description |
|---|---|
| atExit() | Registers a callback function. The registered function is executed when the current process exits. |
| exit() | Exits a process. |
| getCommand() | Obtains the command of the current process. |
| getCommandLine() | Obtains the command line of the current process. |
| getHomeDirectory() | Obtains the path of the home directory of the current process. |
| getProcessId() | Obtains the ID of the current process. |
| getStdErr() | Obtains a standard error stream of the current process. |
| getStdIn() | Obtains a standard input stream of the current process. |
| getStdOut() | Obtains a standard output stream of the current process. |
| getTempDirectory() | Obtains the path of the temporary directory of the current process. |
| getVariable() | Obtains the value of an environment variable with a specified name. |
| getVariables() | Obtains environment variables of the current process. |
| getWorkingDirectory() | Obtains the working path of the current process. |
| removeVariable() | Removes an environment variable by specifying its name. |
| setVariable() | Sets a pair of environment variables for the current process. |
Exceptions
| Name | Description |
|---|---|
| EnvException | Specifies the exception class of the env package. |