web stats
Environment variables different from terminal when calling getenv - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Thread Tools Display Modes
Old 05-24-2019, 06:41 AM
mfortin mfortin is offline
What's HL7?
Join Date: May 2019
Posts: 2
mfortin is on a distinguished road
Default Environment variables different from terminal when calling getenv

Hello guys,

I am trying to set an environment variable to use in Mirth, but it does not show up when I call

var tempdir = java.lang.System.getenv("TMP"); // returns null

{PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin, LANGUAGE=en_CA:en, INVOCATION_ID=bc84eb42ff8e4a7c8ba270c72234b2cc, JOURNAL_STREAM=8:13430, OLDPWD=/usr/lib/jvm/java-8-openjdk-amd64/jre, PWD=/opt/mirthconnect, LANG=en_CA.UTF-8}

There should be other variables here, such as USER and HOME, which also return null when I call getenv("USER").

This is on a fresh Debian 9.9 install in Virtualbox, I installed VB guest additions and Mirth 3.7.1 (sh version) only.

Thanks for your help!

Here is the error log:

[2019-05-24 09:31:36,148] ERROR (com.mirth.connect.server.controllers.DonkeyEngine Controller:1570): Error executing global deploy script.
com.mirth.connect.server.util.javascript.JavaScrip tExecutorException: com.mirth.connect.server.MirthJavascriptTransforme rException: SOURCE CODE:
98: function doScript() {99: var tempdir = java.lang.System.getenv("TMP");100: 101: logger.debug(java.lang.System.getenv());102: 103: globalMap.put("testDir", tempdir);104: 105: var testDir = new Packages.java.io.File(globalMap.get("testDir"));10 6: if (!testDir.exists()) try {107:
testDir.mkdir();LINE NUMBER:
Wrapped java.lang.NullPointerException
at Deploy:103 (doScript)
at Deploy:113
at com.mirth.connect.server.util.javascript.JavaScrip tUtil.execute(JavaScriptUtil.java:75)
at com.mirth.connect.server.util.javascript.JavaScrip tUtil.executeGlobalDeployScript(JavaScriptUtil.jav a:431)
Reply With Quote
Old 05-27-2019, 12:00 PM
mfortin mfortin is offline
What's HL7?
Join Date: May 2019
Posts: 2
mfortin is on a distinguished road

The solution is to add this line

export VAR="value"

in /etc/init.d/mcservice

I'm not sure if that's a nice way to do it though.
Reply With Quote
Old 05-30-2019, 12:51 PM
agermano agermano is offline
Mirth Guru
Join Date: Apr 2017
Location: Indiana, USA
Posts: 1,112
agermano is on a distinguished road

See the following solution. It still requires modifying /etc/init.d/mcservice, but it's a little cleaner as it moves all of your variable declarations to a different file.

Reply With Quote

debian, error, getenv, javascript

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

All times are GMT -8. The time now is 07:41 PM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2020, vBulletin Solutions, Inc.
Mirth Corporation