Functions
func atExit(() -> Unit)
public func atExit(callback: () -> Unit): Unit
Description: Registers a callback function. The registered function is executed when the current process exits.
NOTE
Do not use the atexit function in the C language to prevent unexpected problems.
Parameters:
- callback: () ->Unit: callback function to be registered
func exit(Int64)
public func exit(code: Int64): Nothing
Description: Registers a callback function. The registered function is executed when the current process exits.
Parameters:
- code: Int64: exit status code of the current process
func getCommand()
public func getCommand(): String
Description: Obtains the process command.
Returns:
- String: command of the current process
Throws:
- EnvException: If the process name cannot be obtained because the process does not exist or the process is a zombie process, this exception is thrown.
func getCommandLine()
public func getCommandLine(): Array<String>
Description: Obtains the command line of the current process. This property of the current process can be obtained on Windows. In other scenarios, this property cannot be obtained in non-privileged API mode.
Returns:
Throws:
- EnvException: If the process command line cannot be obtained because the process does not exist, the process is a zombie process, or the scenario is not supported on Windows, this exception is thrown.
func getHomeDirectory()
public func getHomeDirectory(): Path
Description: Obtains the path of the home directory of the current process.
Returns:
- Path: path of the home directory of the current process
func getProcessId()
public func getProcessId(): Int
Description: Obtains the ID of the current process.
Returns:
- Int: ID of the current process
func getStdErr()
public func getStdErr(): ConsoleWriter
Description: Obtains the standard error stream of the current process.
Returns:
- ConsoleWriter: standard error stream of the current process
func getStdIn()
public func getStdIn(): ConsoleReader
Description: Obtains the standard input stream of the current process.
Returns:
- ConsoleReader: standard input stream of the current process
func getStdOut()
public func getStdOut(): ConsoleWriter
Description: Obtains the standard output stream of the current process.
Returns:
- ConsoleWriter: standard output stream of the current process
func getTempDirectory()
public func getTempDirectory(): Path
Description: Obtains the path of the temporary directory of the current process. The values of TMPDIR, TMP, TEMP, and TEMPDIR are obtained from environment variables. If the preceding values do not exist in the environment variables, the /tmp directory is returned by default.
Returns:
- Path: path of the temporary directory of the current process
func getVariable(String)
public func getVariable(key: String): ?String
Description: Obtains the value of an environment variable with a specified name.
Parameters:
- key: String: specified name
Returns:
- ?String: value of the environment variable with the specified name in the current process
Throws:
- IllegalArgumentException: If the function parameter key contains null characters, this exception is thrown.
func getVariables()
public func getVariables(): Array<(String, String)>
Description: Obtains environment variables of the current process. This property of the current process can be obtained on Windows. In other scenarios, this property cannot be obtained in non-privileged API mode.
Returns:
Throws:
- EnvException: If the environment variables of a process cannot be obtained because the process does not exist, the process is a zombie process, or the scenario is not supported on Windows, this exception is thrown.
func getWorkingDirectory()
public func getWorkingDirectory(): Path
Description: Obtains the working path of the current process. This property of the current process can be obtained on Windows. In other scenarios, this property cannot be obtained in non-privileged API mode.
Returns:
- Path: working path of the current process
Throws:
- EnvException: If the working path of a process cannot be obtained because the process does not exist, the process is a zombie process, or the scenario is not supported on Windows, this exception is thrown.
func removeVariable(String)
public func removeVariable(key: String): Unit
Description: Removes an environment variable by specifying its name.
Parameters:
- key: String: name of the environment variable
Throws:
- IllegalArgumentException: If the function parameter k contains null characters, this exception is thrown.
func setVariable(String, String)
public func setVariable(key: String, value: String): Unit
Description: Sets a pair of environment variables. If an environment variable with the same name is set, the original environment variable value is overwritten.
NOTE
In Windows, if the passed parameter v is an empty string, the variable k will be removed from the environment.
Parameters:
Throws:
- IllegalArgumentException: If the function parameter key or value contains null characters, this exception is thrown.