Contact: zeng  @  zegraph.com      Last update: September 2016

ZeScript Usage

You execute a ZeScript module 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 in the Windows OS. The 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" 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 required, 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 executable, but the "zs" extension. Thus, by copying "zs.exe" to a different name, say "my.exe", and creating a module with the same name, i.e., "my.zs", you can make "my.exe" appears as different self-executing programs to end-users, who 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 can 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 can be accessed through the key, e.g.,

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

Note that if the "=" is intended to pass key-value pairs to a script program, no space should be used before or after "=" because the operation system delimits options by space. However you may use the double quote to include spaces in a key or a 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 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 services. 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.