The @os module contains functions and classes for manipulating operating system primitives such as paths, folders, processes, threads, and mutexes.

@os Functions

:normalize(path) #

Normalize a path.

Parameters

Return

Notes

The function does the following:

:dir(root,globs,recursive) #

Get items in a directory (folder).

Parameters

Return

Notes

Each item is like:

{ name : string, exists : boolean, is_folder : boolean, modified : number (timestamp; seconds since Unix epoch), size : number (bytes) }

If recursive is true, each item.name is a path relative to root. If recursive is false, each item.name is just the leaf.

:stat(path) #

Get status of file at path.

Parameters

Return

Notes

Same item format as :dir.

:modify(path,timestamp) #

Change modification time of an existing file.

Parameters

Return

:cd(path) #

Change the current directory.

Parameters

Return

Notes

If path is null, the current directory is not changed (just returned).

:rmdir(path) #

Remove (delete) directory at path, including any contents and subdirectories.

Parameters

Notes

Use @io:remove to remove individual files.

:mkdir(path) #

Create folder(s) at path.

Parameters

:abs(path) #

Get absolute path from partial/relative path.

Parameters

Return

:get_folder(path) #

Get folder from a file path.

Parameters

Return

:get_leaf(path) #

Get the leaf (filename) from a file path.

Parameters

Return

Notes

Returns the same path for filename-only paths.

:get_ext(path) #

Get the extension (everything after the dot) from a file path.

Parameters

Return

:get_name(path) #

Get the name (filename without extension) from a file path.

Parameters

Return

:exedir() #

Get the absolute path of the directory in which the Axiom binary resides

Return

:exepath() #

Get the absolute path of the Axiom binary

Return

:platform() #

Get the platform that the Axiom binary was compiled for.

Return

:getenv(name) #

Get environment variable under name.

Parameters

Return

Notes

Environment variables are inherited from the shell and parent processes.

:putenv(name,value) #

Get environment variable under name.

Parameters

Notes

Environment variables are inherited by subprocesses created by system, run, and exec

:ticks() #

Get time in milliseconds from arbitrary point.

Return

Notes

This is used to do fine-grained timing, not absolute timing.

:sleep(ms) #

Sleep for a specified amount of milliseconds.

Parameters

Notes

This pauses the current thread and allows other threads/processes to preempt it (allows them to jump ahead on the schedule and execute).

:system(cmd) #

Run a command in the underlying shell of the operating system.

Parameters

Return

Notes

The underlying implementation uses system().

Example

if os.platform()=='windows' os.system('dir /b/od') else os.system('ls -ltr') :run(cmd) #

Run a command and capture the output as a string.

Parameters

Return

Notes

Unlike :system, this function suppresses the output and returns it as a string.

:exec(cmd,env) #

Execute a command in the background.

Parameters

Return

Notes

If env if specified, it should be a string like 'name1=value1\nname2=value2\n...\n'.

Unlike :system and :run, this function does not wait for the command to complete.

:find_pid(pattern) #

Find PID for a process by matching name against pattern.

Parameters

Return

Notes

The process name is the name of the executable without leading path or trailing command-line arguments.

:kill(pid) #

Kill a process by PID.

Parameters

Return

:proc() #

Get a bunch of statistics about the machine.

Return

Notes

The object of statistics is like:

{ cpu_usage : number, #0-100%, CPU usage across all cores mem_usage" : number, #0-100% disk_usage : number, #0-100% io_wait : number, #0-100%, CPU time spent waiting for IO clock_freq : number, #in GHz mem_size : number, #in GB disk_size : number, #in GB num_cores : number, num_connections : number #number of TCP connections }

This function currently does not work on all platforms.

@thread Methods

:new(fn,self,args) #

Construct a new thread.

Parameters

Return

Notes

Reading/writing to the same variable from different thread can cause Axiom to crash. It is the responsibility of the programmer to properly use @mutex around shared data.

Example

:hello(name) print 'hello',name+'!' t = os.thread(hello,null,['from another thread']) t.start() t.wait() :start() #

Start the thread.

Return

:wait() #

Wait for thread to finish.

Notes

Blocks current thread until thread has finished.

:done() #

Check if thread is finished.

Return

Notes

Checks asynchronously (does not block current thread).

:kill() #

Kill the thread (stop execution of thread).

Return

:result() #

Get the return value of the function that was called by the thread

Return

Notes

The return value of this method will be null until the thread is finished. However, do not use this method to check if the thread is finished; use :done() or :wait() instead.

@mutex Methods

:new() #

Construct a new mutex.

Return

Notes

A mutex allows code from different threads to synchronize.

:lock() #

Lock the mutex.

Return

Notes

If the mutex is already locked, this will block until the mutex is unlocked.

:try_lock() #

Attempt to lock the mutex, but do not wait for it.

Return

Notes

Unlike :lock, this does not block the current thread.

:unlock() #

Release lock on current mutex.