| Author |
PATH ...
|
mike foo
Greenhorn
Joined: Nov 22, 2003
Posts: 9
|
|
Hi, i am trying to print $PATH variable (linux).i can do it using : String [] path = {"echo","$PATH"}; Process p= Runtime.getRuntime().exec(path); is there a better way ? Cheers. [ November 22, 2003: Message edited by: mike foo ]
|
 |
Ernest Friedman-Hill
author and iconoclast
Marshal
Joined: Jul 08, 2003
Posts: 24039
|
|
Hi Mike, Welcome to JavaRanch! Java doesn't have access to environment variables, so this kind of thing is about all you can do.
|
[Jess in Action][AskingGoodQuestions]
|
 |
Jim Yingst
Wanderer
Sheriff
Joined: Jan 30, 2000
Posts: 18670
|
|
Java doesn't have access to environment variables True in general. However some environment-type info can be found in the system properties. Try this: On my system, the java.library.path does indeed seem to reflect the $PATH (or %PATH% as the case may be). I'm not sure that's guaranteed exactly - but the API for getProperties() does guarantee there will be a java.library.path property, and that it will be a "List of paths to search when loading libraries". So it's worth trying at least.
|
"I'm not back." - Bill Harding, Twister
|
 |
Ernest Friedman-Hill
author and iconoclast
Marshal
Joined: Jul 08, 2003
Posts: 24039
|
|
On Windows, the library search path is the execution path, so this Java feature is a happy coincidence (a useful one, however, that I've never noticed before and which I may use in the future!) But on Linux/UNIX, they're utterly separate (there isn't even strictly a path, anywhere; there's the LD_LIBRARY_PATH environment variable, but the loader generally has other paths it will use too.) Since the poster mentioned Linux, this probably doesn't help.
|
 |
mike foo
Greenhorn
Joined: Nov 22, 2003
Posts: 9
|
|
Originally posted by Ernest Friedman-Hill: On Windows, the library search path is the execution path, so this Java feature is a happy coincidence (a useful one, however, that I've never noticed before and which I may use in the future!) But on Linux/UNIX, they're utterly separate (there isn't even strictly a path, anywhere; there's the LD_LIBRARY_PATH environment variable, but the loader generally has other paths it will use too.) Since the poster mentioned Linux, this probably doesn't help.
yeah ,that is right.It is easy to do that on Windows using System.getProperties(/** key here */); but it's deferent on linux/unix.Ok thanks for the replies :-).I have found my answer . [ November 23, 2003: Message edited by: mike foo ]
|
 |
mike foo
Greenhorn
Joined: Nov 22, 2003
Posts: 9
|
|
Hi, its me again.What i need is that : man ls | col -b I have this : String [] cmd={"/bin/bash","-c","man ls","| col","-b"} ; try{ Process proc=Runtime.getRuntime().exec(cmd); }catch(IOException e){ e.toString(); } Man ... i am sick of it now .Could someone point to correct array :-) ?
|
 |
mike foo
Greenhorn
Joined: Nov 22, 2003
Posts: 9
|
|
|
Does anyone know a way to get rid of the bold charctres .What i am trying to do is to filter a man page and display it in a textArea.
|
 |
 |
|
|
subject: PATH ...
|
|
|