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");
}

Objects

Process

This object contains information on a process being created from Ballerina. This is returned from the exec function in the system module.

Functions

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.

Constants

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

Types

Error

Represents System related errors.

Errors

FileNotFoundError

Represents an FileNotFoundError with a detailed message.

FileSystemError

Represents an FileSystemError with a detailed message.

InvalidOperationError

Represents an InvalidOperationError with a detailed message.

PermissionError

Represents an PermissionError with a detailed message.