Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Yar lag
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 600
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yar,

Did you try the System.setProperty() method?

John.
 
Yar lag
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20529
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use -D to set the property:
 
John de Michele
Rancher
Posts: 600
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20529
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you even read my post? That is THE way of overriding the user.name property.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic