在xul中,如何检索环境变量?

时间:2022-05-27 23:29:28

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

我有一个名为$REP的环境,如何在Linux环境中使用Xulrunner访问这个变量的值?

--udpate

——udpate

attempting with nslEnvironment:

与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.

正如您想象的,它应该输出“/bin/bash”,就像在终端中那样。我还尝试使用get查看它是否只是exist方法出错,但它返回为空。

What can be wrong here?

这里有什么问题吗?

2 个解决方案

#1


4  

Use nsIEnvironment to read (and set) environment variables.

使用nsIEnvironment读取(并设置)环境变量。

#2


-1  

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

看看如何在javascript中设置一个环境变量(您碰巧编辑了它,是随机的!)

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?

也许?

#1


4  

Use nsIEnvironment to read (and set) environment variables.

使用nsIEnvironment读取(并设置)环境变量。

#2


-1  

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

看看如何在javascript中设置一个环境变量(您碰巧编辑了它,是随机的!)

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?

也许?