Module : system
Module overview
This module provides functions to retrieve information about the system and the current users of the system.
Sample
The sample given below uses the functions in the module to get the system-level information.
import ballerina/io;
import ballerina/system;
public function main() {
// Get environment variables.
io:println("Envirionment variable: " + system:getEnv("HTTP_PORT")); // E.g. “80”
// Get the user account name.
io:println("Username: " + system:getUsername()); // E.g. “john”
// Get the user home path.
io:println("User home: " + system:getUserHome()); // E.g. “/home/john”
// Execute an OS command as a subprocess.
system:Process|system:Error proc = checkpanic system:exec("ls", {}, "/", "-la");
}
Detail | Record type to hold the details of an error. |
Process | This object contains information on a process being created from Ballerina.
This is returned from the |
exec | Executes an operating system command as a subprocess of the current process. |
getEnv | Returns the environment variable value associated with the provided name. |
getUserHome | Returns the current user's home directory path. |
getUsername | Returns the current user's name. |
uuid | Returns a random UUID string. |
INVALID_OPERATION_ERROR | Represents the error code for invalid operations |
PERMISSION_ERROR | Represents the error code for permission errors |
FILE_SYSTEM_ERROR | Represents the error code for file system errors |
FILE_NOT_FOUND_ERROR | Represents the error code for file not found |
Error | Represents System related errors. |
FileNotFoundError | Represents an |
FileSystemError | Represents an |
InvalidOperationError | Represents an |
PermissionError | Represents an |