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
PERMISSION_ERROR
FILE_SYSTEM_ERROR
FILE_NOT_FOUND_ERROR

Types

Error

Errors

FileNotFoundError
FileSystemError
InvalidOperationError
PermissionError