Janet 1.5.1-bcd2089 Documentation
(Other Versions: 1.5.0 1.4.0 1.3.1)

OS Module

The os module contains most Operating System specific functionality as well as routines for interacting with the host OS. There is also some functionality for interacting with the file system. The functionality in this module can be much reduced by setting the JANET_REDUCED_OS define in janetconf.h.

Index

os/arch os/cd os/clock os/cwd os/date os/dir os/execute os/exit os/getenv os/link os/mkdir os/rename os/rm os/rmdir os/setenv os/shell os/sleep os/stat os/time os/touch os/which


os/arch cfunction
(os/arch)

Check the ISA that janet was compiled for. Returns one of:

	:x86
	:x86-64
	:arm
	:aarch64
	:sparc
	:wasm
	:unknown

os/cd cfunction
(os/cd path)

Change current directory to path. Returns true on success, false on failure.

os/clock cfunction
(os/clock)

Return the number of seconds since some fixed point in time. The clock is guaranteed to be non decreasing in real time.

os/cwd cfunction
(os/cwd)

Returns the current working directory.

os/date cfunction
(os/date &opt time local)

Returns the given time as a date struct, or the current time if no time is given. Returns a struct with following key values. Note that all numbers are 0-indexed. Date is given in UTC unless local is truthy, in which case the date is formated for the local timezone.

	:seconds - number of seconds [0-61]
	:minutes - number of minutes [0-59]
	:hours - number of hours [0-23]
	:month-day - day of month [0-30]
	:month - month of year [0, 11]
	:year - years since year 0 (e.g. 2019)
	:week-day - day of the week [0-6]
	:year-day - day of the year [0-365]
	:dst - If Day Light Savings is in effect

os/dir cfunction
(os/dir dir &opt array)

Iterate over files and subdirectories in a directory. Returns an array of paths parts, with only the filename or directory name and no prefix.

os/execute cfunction
(os/execute args &opts flags env)

Execute a program on the system and pass it string arguments. Flags is a keyword that modifies how the program will execute.

	:e - enables passing an environment to the program. Without :e, the current environment is inherited.
	:p - allows searching the current PATH for the binary to execute. Without this flag, binaries must use absolute paths.

env is a table or struct mapping environment variables to values. Returns the exit status of the program.

os/exit cfunction
(os/exit &opt x)

Exit from janet with an exit code equal to x. If x is not an integer, the exit with status equal the hash of x.

os/getenv cfunction
(os/getenv variable)

Get the string value of an environment variable.

os/link cfunction
(os/link oldpath newpath &opt symlink)

Create a symlink from oldpath to newpath. The 3 optional paramater enables a hard link over a soft link. Does not work on Windows.

os/mkdir cfunction
(os/mkdir path)

Create a new directory. The path will be relative to the current directory if relative, otherwise it will be an absolute path.

os/rename cfunction
(os/rename oldname newname)

Rename a file on disk to a new path. Returns nil.

os/rm cfunction
(os/rm path)

Delete a file. Returns nil.

os/rmdir cfunction
(os/rmdir path)

Delete a directory. The directory must be empty to succeed.

os/setenv cfunction
(os/setenv variable value)

Set an environment variable.

os/shell cfunction
(os/shell str)

Pass a command string str directly to the system shell.

os/sleep cfunction
(os/sleep nsec)

Suspend the program for nsec seconds. 'nsec' can be a real number. Returns nil.

os/stat cfunction
(os/stat path &opt tab|key)

Gets information about a file or directory. Returns a table If the third argument is a keyword, returns only that information from stat. If the file or directory does not exist, returns nil. The keys are

	:dev - the device that the file is on
	:mode - the type of file, one of :file, :directory, :block, :character, :fifo, :socket, :link, or :other
	:permissions - A unix permission string like "rwx--x--x"
	:uid - File uid
	:gid - File gid
	:nlink - number of links to file
	:rdev - Real device of file. 0 on windows.
	:size - size of file in bytes
	:blocks - number of blocks in file. 0 on windows
	:blocksize - size of blocks in file. 0 on windows
	:accessed - timestamp when file last accessed
	:changed - timestamp when file last chnaged (permissions changed)
	:modified - timestamp when file last modified (content changed)

os/time cfunction
(os/time)

Get the current time expressed as the number of seconds since January 1, 1970, the Unix epoch. Returns a real number.

os/touch cfunction
(os/touch path &opt actime modtime)

Update the access time and modification times for a file. By default, sets times to the current time.

os/which cfunction
(os/which)

Check the current operating system. Returns one of:

	:windows
	:macos
	:web - Web assembly (emscripten)
	:linux
	:freebsd
	:openbsd
	:netbsd
	:posix - A POSIX compatible system (default)