User manual - Scripting_Guide

NAURTECH SMART CLIENTS FOR WINDOWS CE AND POCKET PC
CETerm Scripting Guide Page 19
var mypassword = "secret";
var waittime = 8000; // Milliseconds waiting for each text
// Only login session 1
if (session == 1)
{
// Look for "login" then "password"
expect( session, waittime, "Login", myusername + "\r",
"Password", mypassword + "\r" );
}
}
The expect arguments are session for the session index, waittime for the
milliseconds waiting for each expected text, followed by pairs of expected text
(prompt) and corresponding action(response). If the action is text, it is simply
sent to the host when appropriate. There can be any number of (expected text,
action) pairs as arguments. The expected text can be plain text or a regular
expression.
For a case-insensitive match of “Login”, an appropriate regular expression could
be /login/i Regular expressions use the slash character as a delimiter
rather than double-quote characters. The ‘i' indicates a case-insensitive match.
A more complex action can contain an anonymous function definition such as
var beepMe = function (session) {CETerm.SendIDA("IDA_BEEP_LOUD", 0);
CETerm.SendText("me\r", session ); }
Combining these changes into the expect call would give
expect( session, waittime, /login/i, beepMe,
"Password", mypassword + "\r" );
You might wonder why the SendIDA call in beepMe has a session index of 0
whereas SendText has the actual session argument. In this case we know that
the beep action is not session specific and does not need to be sent to a specific
session. In general, it is always OK to specify a session and it will be ignored for
actions that do not require a value.