Re: Accessing Environment Variables

Nicholas Smith <[email protected]> Sun, 13 Feb 2005 10:49:43 -0600
Newsgroups gmane.comp.java.beanshell.devel
Message-ID <[email protected]>
On Sat, 2005-02-12 at 23:31 -0600, Patrick Niemeyer wrote:
>On Feb 12, 2005, at 8:54 PM, Nicholas Smith wrote:
>
>> Is there some way to access the environment variables from BeanShell?
>> If not, is it possible to access the deprecated System.getenv method?
>
>You can certainly access the System.getenv() method, just as you can 
>access any ordinary Java method in BeanShell.
>
>Also, just FYI, the System.getenv() and System.getenv( name ) methods 
>are no longer deprecated (they have apparently gotten a reprieve).
>
>So don't feel guilty using them ;)
>
>
>Pat

Do I need a different version or maybe configure it a certain way?  When
I run beanshell and try to access an environment variable this is what I
get:

========================================

nicholas@sun:~ $ beanshell
BeanShell 2.0b2 - by Pat Niemeyer ([email protected])
bsh % System.out.println("PATH=" + System.getenv("PATH"));
// Error: // Uncaught Exception: Method Invocation System.getenv : at
Line: 1 : in file: <unknown file> : System .getenv ( "PATH" )

Target exception: java.lang.Error: getenv no longer supported, use
properties instead: PATH

java.lang.Error: getenv no longer supported, use properties instead:
PATH
   at java.lang.System.getenv(java.lang.String)
(/usr/lib/libgcj.so.4.0.0)
   at _Jv_CallAnyMethodA(java.lang.Object, java.lang.Class, _Jv_Method,
boolean, java.lang.Class[], jvalue, jvalue) (/usr/lib/libgcj.so.4.0.0)
   at _Jv_CallAnyMethodA(java.lang.Object, java.lang.Class, _Jv_Method,
boolean, java.lang.Class[], java.lang.Object[])
(/usr/lib/libgcj.so.4.0.0)
   at java.lang.reflect.Method.invoke(java.lang.Object,
java.lang.Object[]) (/usr/lib/libgcj.so.4.0.0)
   at bsh.Reflect.invokeOnMethod(java.lang.reflect.Method,
java.lang.Object, java.lang.Object[]) (Unknown Source)
   at bsh.Reflect.invokeStaticMethod(bsh.BshClassManager,
java.lang.Class, java.lang.String, java.lang.Object[]) (Unknown Source)
   at bsh.Name.invokeMethod(bsh.Interpreter, java.lang.Object[],
bsh.CallStack, bsh.SimpleNode) (Unknown Source)
   at bsh.BSHMethodInvocation.eval(bsh.CallStack, bsh.Interpreter)
(Unknown Source)
   at bsh.BSHPrimaryExpression.eval(boolean, bsh.CallStack,
bsh.Interpreter) (Unknown Source)
   at bsh.BSHPrimaryExpression.eval(bsh.CallStack, bsh.Interpreter)
(Unknown Source)
   at bsh.BSHBinaryExpression.eval(bsh.CallStack, bsh.Interpreter)
(Unknown Source)
   at bsh.BSHArguments.getArguments(bsh.CallStack, bsh.Interpreter)
(Unknown Source)
   at bsh.BSHMethodInvocation.eval(bsh.CallStack, bsh.Interpreter)
(Unknown Source)
   at bsh.BSHPrimaryExpression.eval(boolean, bsh.CallStack,
bsh.Interpreter) (Unknown Source)
   at bsh.BSHPrimaryExpression.eval(bsh.CallStack, bsh.Interpreter)
(Unknown Source)
   at bsh.Interpreter.run() (Unknown Source)
   at bsh.Interpreter.main(java.lang.String[]) (Unknown Source)
bsh %

========================================

Any ideas? 

Nick




-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click