Announcement

Collapse
No announcement yet.

Environment variables different from terminal when calling getenv

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    logger.debug(java.lang.System.getenv());

    {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:
    103DETAILS:
    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)
    [...]

  • #2
    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.

    Comment


    • #3
      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.

      https://unix.stackexchange.com/quest...ment-variables

      Comment

      Working...
      X