4.2. Environment

NppExec allows you to specify the environment (i.e. environment variables) for any program you start from NppExec. You can do it from NppExec's scripts or directly from NppExec's Console window. You can set or remove/restore such environment variables using NppExec's commands ENV_SET and ENV_UNSET.

For example, you can set your own value of PATH:

ENV_SET PATH = C:\temp  // modified

Now you can start cmd.exe (from NppExec's script or NppExec's console) and type "echo %PATH%" to ensure that the value of PATH is now "C:\temp". Type "exit" to exit cmd.exe and then execute this NppExec's command:

ENV_UNSET PATH  // restored

This command restores the initial value of PATH. NppExec does not remove the PATH variable because this variable existed before it was modified with ENV_SET. In the same time, you can create and remove new environment variables:

ENV_SET new_environment_variable = Hello  // created
ENV_UNSET new_environment_variable        // removed

Such environment variables can be used (and modified) by any program you start from NppExec. Also, values of such variables can be used by NppExec in a form of $(SYS.variable_name). For example:

ENV_SET a = My Variable  // created:  a=My Variable
echo $(SYS.a)            // prints:   My Variable
ENV_SET a = aaa          // modified: a=aaa
echo $(SYS.a)            // prints:   aaa
ENV_UNSET a              // removed

I.e. you can use "$(SYS.variable_name)" to read the variable's value and use "ENV_SET variable_name = value" to set the variables's value.

If there is a need to set/modify an environment variable temporarily (in the scope of the current NppExec's script), use "ENV_SET local <var> = <value>". Once the current NppExec's script ends, the previous value of <var> is restored automatically.

Type "help env_set" in NppExec's Console for more details.

Good way to set your environment is to do it inside NppExec's start-up script. You can specify your start-up script in NppExec's Advanced Options. This script will be executed each time Notepad++ starts. For example, you can create similar script:

// don't show NppExec's Console if it's hidden
NPP_CONSOLE ?
// don't output anything within this NppExec's script
NPP_CONSOLE local -
// as we don't output anything, don't print "==== READY ===="
NPE_CONSOLE local -- p-
// set our environment variables
ENV_SET NPPHOME = $(NPP_DIRECTORY)
ENV_SET TCCHOME = C:\tools\tcc
// restore initial value of PATH
ENV_UNSET PATH
// set our value of PATH
ENV_SET PATH = $(SYS.NPPHOME);$(SYS.TCCHOME);$(SYS.PATH)
// clear Console screen
CLS

The first command ("NPP_CONSOLE ?") forbids the Console to be shown if it's hidden - this is usefull at Notepad++'es start-up.

The next command ("NPP_CONSOLE local -") disables any output to the Console within the current NppExec's script, thus making the script to be completely silent.

The next command ("NPE_CONSOLE local -- p-") disables the "==== READY ====" message within the current NppExec's script, so this message is not printed when the script has finished.

The two following commands set new environment variables: NPPHOME and TCCHOME. These environment variables can be used by any program you start from NppExec.

The following command ("ENV_UNSET PATH") restores the initial value of PATH if it has previously been modified by NppExec. Of course, it can not be modified by NppExec before its start-up script is executed, but you may execute the start-up script again (using NPP_EXEC or from the "Execute NppExec Script..." dialog), so it may be important to restore the initial value of PATH before modifying it. Otherwise, the value of PATH may grow again and again - each time you call the start-up script explicitly or execute another script which modifies the PATH variable.

The next command sets the new value of the PATH variable. Now PATH includes both NPPHOME and TCCHOME, so you can type just "notepad++" or "tcc" in order to use Notepad++'es command line switches or to run tcc.

Finally, the last command ("CLS") clears NppExec's Console's output, so the Console will contain no text when you open it.

See also: Environment (heritable) variables [3.8.3].