NetLogo extension to run commands, read and write environment variables
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

NetLogo shell extension

This package contains the NetLogo shell extension.

It lets you do things like:

(Mac) observer> show shell:exec "ls"

(Windows) observer> show (shell:exec "cmd" "/c" "dir")

The included commands are:

  • shell:pwd => reports current working directory
  • shell:cd <directory> => change current working directory (relative to current directory unless begins with a drive letter on Windows or a forward slash on Mac/Unix)
  • shell:getenv <name> => reports value of environment variable
  • shell:setenv <name> <value> => sets environment variable
  • shell:exec <command> (shell:exec <command> <param> ...) => execute command synchronously and report a string of the results it prints to stdout
  • shell:fork <command> (shell:fork <command> <param> ...) => execute command asynchronously and discard the results
  • shell:reset => clears any environment variables set by shell:setenv and returns the working directory to the NetLogo model directory.



The shell extension inherits all the environment variables that were in place when NetLogo was started. That makes shell:getenv very useful for passing the values of ennvironment variables back to NetLogo. HOWEVER, any environment variables set by shell:setenv are local to the shell extension only and will disappear when the NetLogo session is ended. Similarly, the working directory for the shell extension is initially set to the directory in which the NetLogo model is located. Changing the extension's working directory with shell:cd changes the working directory for the extension only. It does not change the working directory for NetLogo itself. That is done with NetLogo's set-current-directory command.

shell:setenv and shell:cd thus work only within the shell extension and are in the service of shell:exec and shell:fork, which do inherit their environment and working directory from the extension's.


Download and unzip to the extensions folder, which is inside the app folder inside the NetLogo program folder. This should create a shell subfolder that contains the shell.jar file and other potentially useful files. The shell.jar file in this package was built under NetLogo 6.0.1 and Java 1.8.

For more information about NetLogo extensions in general, see the NetLogo User Manual.


The Makefile included in this package can be used to create the shell.jar file from the java source file. If you are running it from the app/extensions/shell folder in the NetLogo installation, you can simply enter "make". (Depending on the system, you may need to do this as "administrator".) If you are in any other directory, you will need to first set the NETLOGO environment variable to tell the Makefile where to find the NetLogo installation. For example:

export NETLOGO="/Applications/NetLogo 6.0.1"
export NETLOGO="c:/Program Files/NetLogo 6.0.1"

The "" are required because the directory names contain spaces.

If compilation succeeds, shell.jar will be created.


The shell extension was written by Eric Russell and updated to NetLogo 6.0 by Charles Staelin.

Terms of Use


The NetLogo shell extension is in the public domain. To the extent possible under law, Eric Russell has waived all copyright and related or neighboring rights.