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 How to change the Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "How to change the "user.name" system property?" Watch "How to change the "user.name" system property?" New topic
Author

How to change the "user.name" system property?

Yar lag
Greenhorn

Joined: Apr 14, 2009
Posts: 10
I know you can get the currently logged in user name (in windows or unix) by doing System.getProperty("user.name"). But how exactly is this variable set? Is it set by a system env variable (in unix)? So for example, if I am launching a new process with Runtime.exec("myJavaCommand"). Is it possible to change the user.name variable for that spawned process? Any ideas? Thank you!
John de Michele
Rancher

Joined: Mar 09, 2009
Posts: 600
Yar,

Did you try the System.setProperty() method?

John.
Yar lag
Greenhorn

Joined: Apr 14, 2009
Posts: 10
John thanks for the quick reply, but no that wouldn't work. What I'm trying to do is this:

Process 1 -> Set up a new env with user.name="John"
Process 1 -> Launch a new jvm with the above env
Process 2 -> Starts and read in the user.name and picks up "John"

I hope that makes sense, any ideas how to setup the env?
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19651
    
  18

Use -D to set the property:


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
John de Michele
Rancher

Joined: Mar 09, 2009
Posts: 600
Yar,

I'm not sure you can do it before-hand, if the new JVM is setting the user.name property from the system's environment. I'm curious about why you need to do this; it seems simpler to me to just manage an internal property.

Edit: Well, Rob knows .

John.
kunu patil
Greenhorn

Joined: Sep 24, 2007
Posts: 20
Yar lag wrote:John thanks for the quick reply, but no that wouldn't work. What I'm trying to do is this:

Process 1 -> Set up a new env with user.name="John"
Process 1 -> Launch a new jvm with the above env
Process 2 -> Starts and read in the user.name and picks up "John"

I hope that makes sense, any ideas how to setup the env?


Yar,

Could you please tell me that how did you set new env. variable? Can you tell that how to do it in Windows?

Thanks.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19651
    
  18

Have you even read my post? That is THE way of overriding the user.name property.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to change the "user.name" system property?
 
Similar Threads
Lost on the classpath!
How to set the System variable on WINDOWS and UNIX?
Complete Beginner
NT User Name
Log4J properties in Production