Skip to main content
GameDev.net gamedev.net
🔒 Locked

[java] Find where process was called from

Started by _Sigma Oct 9, 2006 at 5:35 PM 3 replies 700+ views
Original Post
_Sigma
_Sigma
Alright, I'm not completly sure how to phrase this, so please let me know if it doesn't make any sense! I am currently writing a program to add a header to all my .h / .c /.java files, etc. So if I add my folder where my application's .class files are to the system path, i can then do the java myApp. Correct? So I want my program to know what folder it has been called from. What i mean by this is: For example, if, in *nix, do you 'ls' it know what directory it was called from. I am looking for the equiv in java. Hope this made sense!
CaptainJester
CaptainJester
System.getProperty("user.dir");

To get a list of properties use this:
public static void main(String[] args) {    Properties p = System.getProperties();    for(Enumeration en=p.propertyNames();en.hasMoreElements();) {        String temp = (String)en.nextElement();        System.out.println(temp + "=" + System.getProperty(temp));    }}


this works, but truncates some entries:
public static void main(String[] args) {    System.getProperties().list(System.out);}

"None of us learn in a vacuum; we all stand on the shoulders of giants such as Wirth and Knuth and thousands of others. Lend your shoulders to building the future!" - Michael Abrash[JavaGaming.org][The Java Tutorial][Slick][LWJGL][
_Sigma
_Sigma
I can't try that atm, but I assume (given that you replied =)) that will tell me the dir my app was called from?
CaptainJester
CaptainJester
Yes. "user.dir" shows the directory that you were in when you typed the java command. Or where it was called from if someone clicked a jar or ran from an IDE.
"None of us learn in a vacuum; we all stand on the shoulders of giants such as Wirth and Knuth and thousands of others. Lend your shoulders to building the future!" - Michael Abrash[JavaGaming.org][The Java Tutorial][Slick][LWJGL][
_Sigma
_Sigma
Thanks!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.