This week's giveaway is in the EJB and other Java EE Technologies forum. We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line! See this thread for details.
I created a environment variable using: setenv file_name /home/test/a.txt How to access that environment variable from java code. I tried String s = System.getenv("file_name"); I am getting following error when runnig :
Exception in thread "main" java.lang.Error: getenv no longer supported, use properties and -D instead: input at java.lang.System.getenv(System.java:691) at Li.main(Li.java:6)
Than I tried String s = System.getProperty("file_name"); It is giving null as output
First we have to decide whether to use Environment Variables or System Properties. While programming in Java Environment, it is best to use System Properties instead of Env Variables.
Here is the reason,
System properties and environment variables are both conceptually mappings between names and values. Both mechanisms can be used to pass user-defined information to a Java process. Environment variables have a more global effect, because they are visible to all descendants of the process which defines them, not just the immediate Java subprocess. They can have subtly different semantics, such as case insensitivity, on different operating systems. For these reasons, environment variables are more likely to have unintended side effects. It is best to use system properties where possible. Environment variables should be used when a global effect is desired, or when an external system interface requires an environment variable (such as PATH).
~ THE TOUGHEST THING IS TO REMAIN FOCUSED ~
Joined: Jul 06, 2006
What is cmd.exe in the code I am running in UNIX environment When I run the code I am getting following error :
java.io.IOException: cmd.exe: not found at java.lang.UNIXProcess.forkAndExec(Native Method) at java.lang.UNIXProcess.<init>(UNIXProcess.java:52) at java.lang.Runtime.execInternal(Native Method) at java.lang.Runtime.exec(Runtime.java:566) at java.lang.Runtime.exec(Runtime.java:428) at java.lang.Runtime.exec(Runtime.java:364) at java.lang.Runtime.exec(Runtime.java:326) at Sample.getEnv(Sample.java:19) at Sample.main(Sample.java:10)
Joined: Nov 01, 2006
Use the following command For UNIX use : env For Windows/nt : cmd.exe For Windows9x : command.com