Embedthis Ejscript 1.1.2
Home >User Guide> Virtual Machine

See Also

Using the Virtual Machine

The ejsvm command is an embedding of the Ejscript Virtual Machine in a simple command line utility. It can be used to run the module files of previously compiled programs.

Executing Module Files

When ejsvm is invoked with a module file on the command line, that module will be read and its byte code executed. One module may be supplied and the arguments after it will be passed into the script as command line arguments. For example:

ejsvm myModule.mod arg1 arg2 arg3

The script file may be either a script file or it may be an Ejscript module with a ".mod" extension that has been previously compiled with the ejsc command.

Extra Modules

If you require more modules to be explicitly loaded, use the --files "modules ..." switch to supply extra modules. These will be loaded in order, but after the primary module on the command line. For example:

ejsvm --files "module1.mod module2.mod" myModule.mod arg1 arg2 arg3

In most cases, this is not necessary as you can use the "require" directive in your program to cause modules to be loaded as required by the Ejscript loader.

Run a Designated Method

The ejsvm command can also invoke a specific static method on startup. If either the --class or --method switches are supplied, then ejsvm will run the requested static method after the input module initialization and global code has been executed. If the --method switch is omitted, then the "main" method name is used. If the --class switch is omitted, the first class with a static main method is used. For example:

ejsvm --class MyClass --method "main" myModule.mod

This command will load myModule.mod, run the byte code and then invoke the static main method in the MyClass class.

Command Options

The ejs command may be invoked with the following command options:

ejsvm [--class className] [--files "modules..."] [--log logSpec] [--method methodName] 
    [--optimize level] [--searchPath ejsPath] [--version] module [arguments ...]

The ejsvm command will load and execute the given module with the supplied arguments passed into the App.args property.

Switch Description
--class className Use the given className when searching for the startup method specified via --method or "main" by default.
--debug Run in debug mode with symbolic stack backtraces in exceptions.
--files "modules..." Specifies an extra set of files to be compiled. The ejsvm command normally takes just one script file on the command line. The --files switch allows extra script to be compiled after the primary script, but before the scripts are run.
--log logName[:logLevel] Specify a file to log internal execution messages. Ejs will log execution related trace to the log file. The log level specifies the desired verbosity of output. Level 0 is the least verbose and level 9 is the most. Level 2 will include trace of each source statement and assembler instruction executed (provided --nodebug is not specified).
---method methodName Set the startup method name. Defaults to "main" if a --className is specified and --method is not.
--searchPath ejsPath

Override the module search path. The module search path is a set of directories that the ejsvm command will use when locating and loading Ejscript modules. Given a module named "a.b.c" in a script, ejsvm will use the following search strategy to locate the module:

1. Search for a module file named "a.b.c.mod"

2. Search for a module file named "a/b/c.mod"

3. Search for a module file named "a.b.c.mod" in EJSPATH

4. Search for a module file named c.mod in EJSPATH

The search path is initiallly specified via the environment variable EJSPATH and may be overridden via the --searchPath ejsPath switch. EJSPATH and the ejsPath command line value are similar to the system PATH formats. On windows, path segments are separated by ";" and on Linux, Unix, FreeBSD and MAC, the path segments are separated by ":" delimiters.

--version Print the ejsvm command version and exit.

© Embedthis Software LLC, 2003-2012. All rights reserved. Embedthis, Ejscript and Appweb are trademarks of Embedthis Software LLC.