Console
For those who know Forth language, console is a tool allowing interactive communication with nnCron; for those who only starts to learn Forth, console is an indispensable assistant. In console you can use all Forth words, create new definitions and execute them etc. But please be careful: Forth allows you to do a lot of things, therefore it requires extreme care.
To start the console, right-click on nnCron icon in system tray and select Tools - Console in the menu. Console can also be started from command line.
If you want console to be started automatically at nnCron startup, open Options dialog window and check checkbox Open at startup on Interface page.
To end a console session and quit console type:
BYE
and press ENTER; or you can just click on the Close button in upper right corner of console.
nnCron console "remembers" all the commands you enter and can recall these commands and maintain command history list using pre set hotkeys. For example, you can press F7 to display the list of available commands in history. Press Up Arrow to recall the command you used before the one displayed. Press Down Arrow to recall the command you used after the one displayed etc... Take a look into description of built-in command doskey in your operating sysytem documentation for detailed list of available hotkeys.
Since nnCron version 1.88, one can use console even from remote computers. For this purpose, nnCron starts Remote Console server at each startup. Behavior of remote console server is modified with the following variables of nncron.ini:
After you made sure you have right to connect from your address and that you know which port to connect to, start telnet and type in the command:
open <ip_address> <port>
for example:
open 127.0.0.1 2002
In this way, you will start a remote console sessions which is just the same as a local session.
Console can also be started and closed programmatically. In nnCron scripts which are started from command line with the help of -runfile key, one can use following words of Forth language:
CONSOLE - create a console window
START-QUIT - run word QUIT in a separate thread
QUIT - if a console is already running
Example:
: main CONSOLE ." Hello, World!" CR ." Press any key..." KEY DROP ;
When working with Forth console, please keep in mind that most of predefined prefix-type words in nnCron are intended to be used at compile-time rather then at run-time. Each task is automatically compiled when crontab is reloaded. So these words can be compiled, but cannot be used in console.
Here is a simple example. In a Forth console window, type the following line
MSG: "test"
and press ENTER. If you expect to see a message box saying "test", you are mistaken, for we used word MSG: at run-time and not at compile-time.
But if you compose a definition for a new word in console itself:
: test_message MSG: "test" ;
then press ENTER and and now try to execute this word,
test_message
then you will get your message box saying "test". Why? Well, it is because we compiled a new word by pressing ENTER after its definition, i.e. we used word MSG: only at compile time.
Besides that, you can use in console a postfix-type analogue of word MSG:
S" test" MsgBox
Most of predefined prefix words in nnCron have versions that use postfix positioning; you can safely use these postfix words in console.
In order for nnCron console to work correctly, you must have TCP/IP protocol installed. If it is not installed on the computer where you are working, you can use so-called local console instead of the standard nnCron console. In order to be able to use the local console, set variable RemConsole in nncron.ini to OFF:
RemConsole OFF
In this case, a local console will be opened instead of standard nnCron console. The only limitation you will encounter in working with the local console is that is you shouldn't try to close it with Close button in upper right corner of console window.
The proper way to close a console window is to type the word bye in lower case:
bye
and press ENTER.
Don't to close local console by clicking on Close button in the upper right corner, for this will close nnCron itself!
A Few Useful Words to Use with Console:
. (period)
Grabs the value on the top of stack, removes it from the task and prints it to console.
Examples:
\ let's print to console the result of a check for existence of a file FILE-EXIST: "c:\xxx\test.sem" . CR \ let's print to console the result of addition 2 3 + . CR
.S
Outputs all the contents of the stack without destroying it (i.e. leaving the stack in its former condition)
Example:
\ placing integers on stack and printing them to console 1 2 3 4 5 6 7 8 9 0 .S
ABRACADABRA
Clears the stack. Actually, any inexistent word can be used to clear the stack, including ABRACADABRA or CLEAR_DA_STACK or even simply qwefdawdflk. :)
Example:
\ placing integers on stack 1 2 3 \ clearing the stack shg
We can also define a special word for clearing the stack. Let's call it 0SP.
: 0SP BEGIN DEPTH WHILE DROP REPEAT ;
Word DEPTH returns the number of elements on the stack. In this loop,
we execute word DROP until word DEPTH returns 0 (which
means that the stack is already empty).
Place this definition, for example, to plugin tools.spf,
and you will always have word 0SP at your disposal.
."
This word prints to console a succeeding string from the current task followed a closing quotation mark.
Examples:
#( test_debug NoActive Action: ." Test string." CR ." Debug message." CR )#
Here are examples of a construct which allows to print to console strings containing predefined nnCron variables:
\ prints to console: "Hello, name_of_current_user!" S" Hello, %USERNAME%!" EVAL-SUBST TYPE \ prints to console the title of currently active window S" Title of active window: %ACTIVE-WINDOW%" EVAL-SUBST TYPE
CR
Types a carriage return in a console window.
Example:
." First string" CR ." Second string" CR
Closes console without closing nnCron. To close console, type in it:
BYE
and press ENTER.