Operating System
The Operating System toolbox connects a graph to the computer it runs on. It reads and writes files and folders, builds paths, prints to and reads from the console, writes and reads binary data byte by byte, and reads the program's command-line arguments and environment variables.
Use it for script-like work: rename a folder of files, read a text file line by line, write a log, or save data in a binary format another program expects.
- Included in: Divooka Explore and Divooka Compute, every tier. In Compute, start a document from the General Purpose workload, or add the Platform reference with Add reference (
Ctrl+Shift+L). The Platform reference holds Operating System and Metaprogramming. - Maturity: Stable · Support: Tier 1 (proposed) · what these mean
- Open it: node library (
Ctrl+Shift+Space) → Operating System, or search for a node withCtrl+Space. - Examples and reference:
Ctrl+Shift+E→ Basics and File System · node reference
New to graphs? Start with Your first program.
Main ideas
The console is for text in and out. Print Line writes a line; Print writes without ending the line; Read Line waits for a line typed into the console dock.
Paths are text. Combine joins folder and file names with the right separator; Get File Name, Get Extension and Get Directory Name take a path apart.
Binary data is written and read in order. An Output Buffer collects typed writes (text, integers, numbers) and saves them to a file. An Input Buffer reads them back. The reads must match the writes in order and width.
Example: ask a question
Open Basics > Read Line (Ctrl+Shift+E). Its graph Greet is a Routine graph with three steps:
- Print Line asks
What is your name?. - Read Line waits for a line in the console dock.
- Print Line greets whoever answered. If nothing was typed, it greets a stranger.
Run it with F5, type a name in the console dock and press Enter. If you press Ctrl+D instead, the console shows:
What is your name?
Hello, stranger!
Example: write and read a binary file
Open File System > Binary Data Reading and Writing. It is a Routine:
- Make Output Buffer starts an empty buffer.
- Write String Fixed Size writes
DATA; two Write Int nodes write a version and a count. - Save writes the buffer to a file beside the document.
- From File reads the file back into an Input Buffer.
- Read String and two Read Int nodes read the values in the same order, and Print Line prints them:
Magic: DATA
Version: 1
Count: 16
To use your own data: change the writes and keep the reads in the same order. A file has no header that says what is in it; your reads must agree with your writes.
More examples to open
| Example | What it shows |
|---|---|
| Basics > Standard Input Output 1 | Print and Read Line on one line |
| Basics > Standard Input Output 2 | Several lines at once |
| File System > Binary PPM Image Writing | An image file written byte by byte |
Tips and limits
- File nodes act on real files. Delete, Move and the Write nodes change files on disk with your permissions. There is no undo.
- Paths depend on the system. Use Combine rather than typing a backslash or
/, so the graph also runs on Linux. - Program Arguments gives the arguments the program was started with, for example by
stewor as a published program.
Goes well with: Basic for loops over files, File Conversion to change file formats.
What is in the toolbox
| Category | Some of its nodes |
|---|---|
| File System | Append All Lines, Append All Text, Append Text, Change File Extension and 71 more |
| Input Buffer | Clone, Equals, Bytes, Endianness and 44 more |
| Output Buffer | Make Output Buffer, Clear, Equals, Endianness and 25 more |
| Path | Alt Directory Separator Char, Directory Separator Char, Invalid Path Chars, Path Separator and 22 more |
| Mutable Constructive Byte Array | Make Mutable Constructive Byte Array, Clear, Dispose, Endianness and 21 more |
| Console | Print, Print Value, Print Line, Read Line |
| Runtime Environment | Program Arguments, Get Environment Variable |
See also
- Operating System node reference
- Working with binary data
- Running and the console
- Toolboxes - every other toolbox.