os
The computer TB runs on: your program's arguments, environment variables, running other programs, and exiting.
os.run needs the TB app on your computer. In the playground, os.platform is "browser".
import os
Example
import os
say(f"Running on: {os.platform}")
say(f"Arguments: {os.args}")
say(os.env("TB_EXAMPLE_SETTING", "not set"))
Functions
env(name, default?)
returns textAn environment variable, like env("HOME"), or default (nil) if it isn't set.
run(command, options?)
returns mapRun another program and wait for it. Gives back {"code", "out", "err"}: the exit code (0 means it worked) and what it printed. A text command goes through the system shell, so pipes and wildcards work: run("ls -l | head"). Never build that text from untrusted input. A list runs the program directly with exactly those arguments, with no shell: run(["ping", "-c", "1", host]). Prefer this whenever input comes from outside. options: {"timeout": seconds, "cwd": folder, "input": text to send it}. Not available in the browser playground.
quote(text)
returns textMake text safe to put inside a shell command for os.run (mac/linux shells).
exit(code?)
Stop the program now. 0 (the default) means all went well.
Values
| Name | Value | What it is |
|---|---|---|
os.args | depends on the computer | The words after the file name: tb main.tb a b gives ["a", "b"]. |
os.platform | depends on the computer | "windows", "mac", "linux" or "browser". |
os.user | depends on the computer | The name of the person logged in to this computer. |
os.script | depends on the computer | The path of the running .tb file ("" in the REPL). |