2

I have an environment called $REP, how can I access the value of this variable using Xulrunner in a Linux environment?

--udpate

attempting with nslEnvironment:

var env = Components.classes["@mozilla.org/process/environment;1"].getService(Components.interfaces.nsIEnvironment);
dump("bash=" + env.exists("BASH") + '\n');
dump("bash=" + env.exists("$BASH") + '\n');

the output was:

bash=false
bash=false

as you imagine, it should output "/bin/bash" as it does in the terminal. I also tried using get to see if it was just the exists method wrong, but it returned empty.

What can be wrong here?

The Student
  • 27,520
  • 68
  • 161
  • 264

2 Answers2

4

Use nsIEnvironment to read (and set) environment variables.

Neil
  • 54,642
  • 8
  • 60
  • 72
  • 1
    `BASH` isn't an environment variable, it's a shell variable. (Compare the output of `set` and `env`.) – Neil Feb 11 '11 at 21:18
-1

Have a look at Setting an environment variable in javascript (which you happened to edit, randomly!).

I very much doubt you'll be able to read these variables from a browser environment though.

edit:

var oShell = WScript.CreateObject("WScript.Shell");
var oSysEnv = oShell.Environment("SYSTEM");
WScript.Echo (oSysEnv("PATH"));

perhaps?

Community
  • 1
  • 1
akiller
  • 2,462
  • 22
  • 30
  • if you see the source of what I edited, you'll se that I removed the < pre > and add the code formating, so it gets the sintax hightlight.. ;) Also, as you see, I already saw that question and the answers, but there's nothing about how to read. Thanks for the second line of your answer, maybe it's not possible.. – The Student Feb 10 '11 at 12:53
  • I didn't know about that, I'm reasonably new to this :o. – akiller Feb 10 '11 at 12:56
  • It throws "WScript not defined". Actually, I didn't understand fully this script. I imagine I'm just supposed to change the "PATH" value with my variable's name, I tried the system variable "BASH", but the problem occurred on the first line with WScript. – The Student Feb 10 '11 at 13:10
  • This is only available in Windows in Internet Explorer (or anything that uses JScript). – sdwilsh Feb 12 '11 at 15:36