Contact: zeng  @  zegraph.com      Last update: 20 January 2010

ZeScript Usage

A ZeScript module may be executed by a command in a console window, e.g.,

C:\zs>zs.exe modulename

That, of course, assumes ZeScript being installed in the C:\zs directory. A module name is the name of a script file (the extension may be omitted) and a script file name must have ".zs" extension. In the above example, there must be a script file named "modulename.zs" and saved in C:\zs, C:\zs\cls, or C:\zs\lib, or C:\zs\cgi. To execute a module in any other directories, the full path to the module is necessary, e.g.,

C:\zs>zs.exe d:\myscript\mymodule

If no module name is given, ZeScript tries to execute a module having the same name as the virtual machine program. Thus, by copying "zs.exe" to a different name, say my.exe, and creating a module with the same name, you can make zs.exe appears as different programs to end-users: they may just click my.exe to execute my.zs.

When you execute a module by a command line with options, e.g.,

C:\zs>zs.exe module opt1 name=John age=45 opt2

the program name, the module name, and the options are saved in an array that may be accessed by the primitive function getarg(key). That is

getarg(0); //returns zs.exe as string
getarg(1); //returns module as string
getarg(2); //returns opt1 as string
getarg(3); //returns name=john as string
getarg(4); //returns age=45 as string
getarg(5); //returns opt2 as string

When an option contains the "=" character, the parts before and after "=" are also saved as a key-value pair and the value may be accessed through the key, e.g.,

getarg("name"); // returns John as string

Note that no space should be used between "=" and the key or value because otherwise the DOS will pass them to the program as separate options. However you may use the double quote to include space in key or value:

C:\zs>zs.exe module opt1 "my name=John Kerry" age=45 opt2

Windows NT Service

The program ntservice.exe included in the ZeScript package is for runing ZeScript as a Windows NT (NT4.0, WIN2000, WIN2003, XP, VISTA) service. Here are the procedures:

  1. Prepare a script program that does not exit. For example:
          ....
          while(1) {
            // do something here
            sleep(1000)
          }
          ....
    
  2. Create a NT service using sc.exe, a Windows utility program for managing NT services. (If your NT4.0 or WIN2000 does not have it, copy one from XP in the system32 directory.) For example:
          sc.exe create ServiceName binPath= "path_to_ntservice.exe ServiceName zs.exe script.zs arg1 arg2 ...."
    
    When the service is activated, it will create a process to execute the command "zs.exe scrupt.zs arg1 arg2 ..."
  3. Start the service from Windows' control panel or by the command:
          sc.exe start ServiceName
    
    And if necessary, change the service type from manual start to auto start from the control panel.