Starting a Task

As explained in preceding sections, task is a construct built in compliance with certain syntactic rules, defining the actions to be performed and conditions which should be present in order for these actions to be performed.

The actions are defined in Action: section of the task. And what about conditions? What tools can a user employ in order to start an application at the precise moment when it should be started? Within the task itself (i.e. while defining the task) a user has control over the following:

All these task components are described in detail in their respective chapters of this Help file. In addition nnCron provides the capability to start a task "from outside world", or manually.



Starting a Task Manually from nnCron GUI

This is just as simple as it can be. Instructions for starting a task manually with the help of GUI can be found here.

Sometimes it becomes necessary to create a task a task which can be started only manually. To make sure that it never starts automatically, include option NoActive.

See also Note.


Starting a Task from Command Line

Start nnCron from command prompt with key -run <task_name>.

nncron.exe -run my_first_task

The task will be executed. If nnCron was already running when you were typing this command, the task will be started by existing instance of nnCron. If nnCron was not running, then this command will start nnCron, cause it to re-read crontabs, start the specified task and unload nnCron from the memory.

Of course, in order to be able to start a task from a command prompt, it is necessary for this task to be present in one of the active crontabs.

See also Note.

Sometimes it may be more convenient to use nnCron's capabilities to define and run Forth words right from the command line.


Calling a Task from Another Task

nnCron provides a capability to start executing Action: section of one task from the body of another task. In order to do this, it is necessary to place the callee task higher in the crontab (closer to beginning) than the caller task. It follows, then, that both tasks (of course) must be in the same crontab file.

Use nnCron's keyword <task-name> RUN in order to execute Action: section of the callee task as a subprogram, e.g. in the same thread as the rest of instructions of the caller task.

Example:

#( hello
\ ...
Action: MSG: "Hello, friend!"
)#

#( task2
\ ...
Action: hello RUN 
)#

Please note, that word 'RUN' calls only 'Action:' section of the outer task, and not the entire task!

And if it becomes necessary to start an external task in its entirety (asynchronously, in a separate thread), with authorization and with check for all conditions (excluding time-conditions - Time:, OnceA* etc), you can use word <task-name> LAUNCH.

Example:

#( hello
\ ...
Action: MSG: "Hello, friend!"
)#

#( task2
\ ...
Action: hello LAUNCH
)#

Word LAUNCH is convenient to use in order to start a task from nnCron Console.


Running a Task as a Separate Script

A task can be defined in a separate file and executed as a script (or a batch file) afterwards. In order to run such a script file, type at the command prompt:

nncron.exe -runfile script_filename

In order to be able to run a script, it must contain Forth word main.

Example:

\ --- start of script file ----
: main
MSG: "Hello, WORLD!"
SEND-KEYS-DELAY: 100 100
SEND-KEYS: "$r{DELAY 1000}ping localhost -t{ENTER}"
5000 PAUSE
SEND-KEYS: "^c"
;
\ --- end of script file ------

Note: Please remember that by starting a task manually, you cancel all the conditions (Time:, Rule:, Watch*) defined in this task. Your instruction to "execute task manually" has an absolute priority over the rest of conditions! And if you need to check some conditions when starting a task manually, just put them inside the Action: section. For example, the following task will not check the condition when started manually:

#( test_rule
Rule: PROC-EXIST: "notepad.exe"
Action:
    MSG: "Notepad exists!"
)#

And the following task will check the condition even when started manually:

#( test_rule1
Action:
PROC-EXIST: "notepad.exe"
IF 
    MSG: "Notepad exists!"
THEN 
)#

See also: