Table of Contents

Command line interface

Workcraft command line usage is as follows workcraft [OPTIONS] [FILES]

Note that file path parameters CONFIG, SCRIPT and FILES are relative to the working directory.

since v3.3.8 Use environment variables WORKCRAFT_CONFIG and WORKCRAFT_CONFIG_ADD as lower priority alternatives to command line options -config: and -config-add: respectively.

since v3.4.0 To run Workcraft with a specific version of Java Runtime Environment supply it in jre subdirectory of Workcraft installation. If this directory is not found or if WORKCRAFT_USE_NATIVE_JAVA environment variable is defined, then a natively installed Java is used.

Special symbols in file names

If your command line refers to a path containing spaces or other suspicious symbols, then surround it by quotation marks (both ' and " are supported). For example, if you want to set a working directory to "C:\Workcraft Projects" and run a script "Example scripts\test1.js" in there, then Windows command line would look as follows:

workcraft.bat -nogui -dir:"C:\Workcraft Projects" -exec:'Example scripts\test1.js'

Note that backslash symbols \ in scripts (e.g. in a Windows file path) need to be escaped as in this example (notice the double backslashes):

test1.js
work = load("models\\test1.work");
stat = statModel(work);
write(stat, "C:\\Temp\\test1.txt");
exit();

Alternatively, Unix-style file hierarchy separator / can be used, as it does not require escaping and is recognised in all Linux, OSX and Windows:

test1.js
work = load("models/test1.work");
stat = statModel(work);
write(stat, "C:/Temp/test1.txt");
exit();

In the above examples "Example scripts\test1.js" and "models\test1.work" are relative to the working directory "C:\Workcraft Projects", while the file "C:\Temp\test1.txt" is specified by its absolute path.

Examples of working with scripts

Examples of custom config

Reuse running Workcraft instance

In order to reuse the same instance of Workcraft for opening .work files from a command line use -port:NUMBER option. This will enable Workcraft to check if its instance is already running and listening on that port, and if this is the case, pass data to the running instance via the specified port.

For example, the following sequence of commands would first start Workcraft on port 12345, then open file.work, and finally execute script.js, all in the same instance of Workcraft (so script.js can refer for model in file.work):

workcraft -port:12345
workcraft -port:12345 file.work
workcraft -port:12345 -exec:script.js

This feature is is also convenient when associating .work files with Workcraft, so they can be open directly from a file browser. By default, a new instance of Workcraft would start each time a .work file is open this way. If you prefer to reuse a single instance of Workcraft, this can be achieved by hard-coding an unoccupied port number directly into workcraft runner script (e.g. add -port:12345 just before -dir: option).