website is under construction
Standard Library

OS

import "ghost:os"
import { args, exit, sleep } from "ghost:os"

The os module covers the program's own relationship with the machine running it: the arguments it was given, pausing, ending, and which operating system it is on.

Methods

os.args()

Returns a list of the command line arguments the interpreter was given, as strings. The first element [0] is the path of the script being run; anything after it is what the caller passed along.

os.args()

os.exit()

Causes the current program to exit with the given status code and optional message. Conventionally, code zero indicates success, non-zero an error. The program terminates immediately.

For portability, the status code should be in the range [0, 125].

os.exit(0, "Process completed successfully")

// expected output: Process completed successfully

The message is optional; os.exit(1) exits quietly. Arguments are validated before anything is printed, so a miscall does not half-run. Nothing deferred runs either — the process ends immediately.

os.sleep()

Pauses for the given number of milliseconds. A negative duration is a value error.

// Pause for one second
os.sleep(1000)
Pausing lives here rather than on date: stopping the program is something the program does, not something a calendar instant does. Reading the clock is date.now().

Properties

os.name

Returns the name of the current operating system:

  • darwin (macos)
  • linux
  • windows
os.name

// expected value: darwin