File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes PATH ... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Java in General
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: 24166
    
  30

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: 18671
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: 24166
    
  30

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