Skip to main content
rombanks
Inspiring
October 15, 2015
Answered

ES does not recognize an environment variable

  • October 15, 2015
  • 1 reply
  • 1404 views

Hello fellows,

On my Win 7 system, I've redefined the HOME environment variable as C:\Users\bnks (by default, it's C:\Documents and Settings\Users\bnks).

I'd like to save an FM file to C:\Users\bnks\Checkout\Test\, so in my extendscript, I've defined the following variable:


var docLib = "~\\Checkout\\Test\\";


where the tilde (~) should be parsed by extendscript as the HOME environment variable (according to Chapter 3, “File System Access” in the JavaScript Tools Guide).


Unfortunately, the tilde is ignored when I try to save the file:

...

var dname = docLib + rName + ".fm";

doc.Save(dname, saveParams, returnParams);

...


Any idea why this happens?


Thank you!!!



This topic has been closed for replies.
Correct answer JoH

The tilde doesn't work for me either (FM11), but you can get the value of an environment variables with $.getenv():

var docLib = $.getenv("HOME") + "\\Checkout\\Test\\";

1 reply

JoHCorrect answer
Inspiring
October 16, 2015

The tilde doesn't work for me either (FM11), but you can get the value of an environment variables with $.getenv():

var docLib = $.getenv("HOME") + "\\Checkout\\Test\\";

rombanks
rombanksAuthor
Inspiring
October 19, 2015

Hi JoH,

Thank you for your response and for the suggestion! It does work. I wonder why tilde doesn't.

BTW, why is the $ sign used before the getenv(" ") function?

Thanks!

Klaus Göbel
Legend
October 19, 2015

Hi rombanks

BTW, why is the $ sign used before the getenv(" ") function?

have a look at:

Chapter 8, page 216, “Dollar ($) object” in the JavaScript Tools Guide