Chapter 1. How to execute a single instruction?

To display Hello world on the system console we use the following instruction in Obix:

system.console.write_line ( "Hello world" )

A single instruction can be executed through an operating system command that calls Obix. To do this, proceed as follows:

In the above example we launch Obix and provide two command line arguments. The first argument, execute_instruction, specifies the name of a command that Obix should execute. The second argument specifies the instruction we want to execute.

[Note]Note

Instead of writing execute_instruction you can also simply write ei, which is a short name, or abbreviation, for execute_instruction. Most commands in Obix have a long name for best readability (to be used in batch files, for example), and a short name equivalent for less keystrokes.

From now on we will use the term 'Linux' instead of 'Unix-like system', because most Unix users use Linux. The following instructions given for Linux are also valid for any other Unix-like system.

Instead of writing ./obix.sh in Linux, you can also simply write obix if the directory of file obix.sh is included in the system's path.

The above system command takes some time to execute, because the Obix environment has to be loaded, and the source code has to be translated into Java binary code. Later in this tutorial, you'll see how to write code that executes much faster.


Besides executing an instruction to display Hello world, you can also ask Obix to evaluate an expression by using Obix's evaluate command (or its short name ev). In our case the expression is just a simple string literal. Hence, you can execute the following command in your operating system console:

on Linux:
./obix.sh evaluate '"Hello world"'

on Windows:
obix evaluate "\"Hello world\""

The result of evaluating an expression is always sent to the system's out device. By default, the system's out device is the system console. Therefore, executing the above instruction will display Hello world on the system console

To store the result of your expression in file tests/hello.txt, you can redirect the operating system's out device. First, create a subdirectory tests under Obix's root directory, to store any test files. Then use the operating system's redirection symbol > to redirect Obix's output. Finally, display the file's content on the screen, as follows:

on Linux, type:
mkdir tests
./obix.sh evaluate '"Hello world"' > tests/hello.txt
cat tests/hello.txt

on Windows, type:
md tests
obix evaluate "\"Hello world\"" > tests\hello.txt
type tests\hello.txt

Just to give you a taste of what else you can do, here are some more examples (without explanations):


Executing a single instruction or evaluating a single expression is of course of very limited usage in practice. Therefore, the next level of executing code is to execute a set of instructions, as explained in the following chapter.