Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

PATH ...

 
mike foo
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mike,
Welcome to JavaRanch!
Java doesn't have access to environment variables, so this kind of thing is about all you can do.
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic