In xul, how to retrieve an environment variable?

一个人想着一个人 提交于 2019-12-10 23:13:05

问题


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?


回答1:


Use nsIEnvironment to read (and set) environment variables.




回答2:


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?



来源:https://stackoverflow.com/questions/4957251/in-xul-how-to-retrieve-an-environment-variable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!