This week's giveaways are in the MongoDB and Jobs Discussion forums.
We're giving away four copies of Mongo DB Applied Patterns and 4 resume reviews from Five Year Itch and have the authors/reps on-line!
See this thread and this one for details.
The moose likes Java in General and the fly likes PATH ... Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of Mongo DB Applied Patterns this week in the MongoDB forum
or a resume review from Five Year Itch in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "PATH ..." Watch "PATH ..." New topic
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
    
  13

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
    
  13

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.
 
I agree. Here's the link: http://jrebel.com/download
 
subject: PATH ...
 
Similar Threads
Help!!! I can't acces my class from JSP without a package
Javac task and Javac path
Scrabble... it only takes a minute...
Macro recorder plugin/support/api for Swing application?
javac not recognized as an internal or external command