The OS module provides a high-level API for interacting with the operating system, managing environment variables, and controlling processes. It wraps the low-level __native_ system calls into a clean, object-oriented interface.
To use it: include std/os.gw.
The static OS class contains all system-related utility functions.
Termitanes the program immediately with the specified exit code.
- code: Exit status (usually 0 for success).
Returns the Process ID (PID) of the current GW instance.
Attempts to terminate a process by its ID using native system commands (taskkill on Windows, kill -9 on Unix).
- Returns: The output or error message from the system command.
Executes a shell command and returns its standard output.
- command: The raw shell command to execute.
- Returns: The output as a string.
Retrieves the value of an environment variable.
- name: The variable name (e.g.,
"PATH").
Sets or updates an environment variable for the current process.
Returns the current working directory of the process.
Returns the platform name: "Windows", "Linux", or "Mac".
Checks if the OS is Windows.
Checks if the OS is Linux.
Checks if the OS is macOS.
Returns the network name of the computer.
Returns the name of the currently logged-in user.
# Print system info
println("Platform: " + OS.getPlatform());
println("User: " + OS.getUsername());
println("PID: " + OS.getPID());
# Work with environment
var path = OS.getEnv("PATH");
OS.setEnv("MY_VAR", "GW_Power");
println("New variable: " + OS.getEnv("MY_VAR"));
# Execute command
var files = OS.exec(OS.isWindows() ? "dir" : "ls");
println("Current files:\n" + files);
# Exit with error if needed
if (OS.getHostName() == "Forbidden") {
OS.exit(1);
}