© Tyl Software Foundation 2019-2021
▶ PROCESS MODULE
Overview
Tyl Process Module is used for running executable programs, also known as
processes. These processes are programs that exist locally on the same
machine that runs a Tyl program, and can handle tasks that Tyl does not
support, or anyway are written already in another programming language
and do them properly. Moreover, Tyl has the ability to run also an executable
program that was created from a Tyl
program.
Working with Single Process Modules
Declaration and initialization of single
process module:
process 'state.reset.exe'
process.execute
For
In line
This type of process execution is good for a launch and forget missions where we rely on the process to execute its tasks, and do not need to verify or get a result of its activities.
The second argument of
Say we have an
process
module the order of its variables is: path
and arg
, therefore,
path
will get the
relative path of
the program to be executed, will be referred to as the process.
In line
process.execute
, we call execute
function of process
module.
execute
causes the system to execute the process, and continue
immediately with program execution, meaning it is done asynchronously.
This type of process execution is good for a launch and forget missions where we rely on the process to execute its tasks, and do not need to verify or get a result of its activities.
The second argument of
process
, is its process arguments. There are
two types of arguments that process
accepts: scalar and list. scalar
argument means that the argument given is a
scalar, and list means a
list.
Say we have an
addcalc
process that does addition calculation,
sqrtcalc
that does square root calculation, and a calculator.tyl
program
that uses these processes:
! addcalc.exe
in0 number.of in 0
in1 number.of in 1
io.write 'add.result' in0 + in1
! sqrtcalc.exe
in0 number.of in 0
io.write 'sqrt.result' math.sqrt in0
! calculator.tyl
process 'sqrtcalc.exe' 10
process.execute
acargs 10 20
process 'addcalc.exe' acargs
process.execute
As described in working with executables
page, input arguments come as string
scalars, so we have to turn them into numbers, using
In
In line
All these executions are executed asynchronously, and the result files are created in the background.
If it is necessary to verify process execution, or anyway get a result of it, we use
number.of
system
function.
In
calculator
program there are two initialization lines of process
.
In each line, the first token is the module name 'process', meaning that
process
is a single module, also known as static or
singleton. All access to its variables and functions will be in the
format process.variable
and process.function
respectively.
In line
process 'sqrcalc.exe' 10
, we intialize process
with the
process and with the scalar argument 10. After execute
, a
result file 'sqrt.result' is created. In line
process 'addcalc.exe' acargs
, we give a predefined acargs
list
as the list argument. After execute
, file 'add.result' is created.
All these executions are executed asynchronously, and the result files are created in the background.
If it is necessary to verify process execution, or anyway get a result of it, we use
run
execution function:
process 'state.get.exe'
result process.run
run
function causes the system to wait until process execution
is finished. run
result will be the output of the process, in case of a
successful execution, or a system error message. If there is no output
from the process, the result will be an empty string.
This type of process execution is called a synchronous operation, and it gives you the ability to proceed with program execution, based on the result of the execution.