• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Running set variable = value command through Java

 
Inderjeet Dhody
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
I am able to execute echo, set and other windows command prompt commands through Java Program. Can anyone help to execute "set variable = value" command. Its not changing variable value to some other value.
Thanks
Inderjeet
 
Michael Morris
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Inderjeet Dhody:
Hello,
I am able to execute echo, set and other windows command prompt commands through Java Program. Can anyone help to execute "set variable = value" command. Its not changing variable value to some other value.
Thanks
Inderjeet

I doubt that there is a way to do that. The JVM runs in a separate process with a separate shell. Any process that is spawned from the JVM with Runtime.exec() should inherit the environment of the JVM though.
 
Inderjeet Dhody
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Micheal,
Yeah thats fine..JVM runs in separate shelll...so wat abt if I want to change environment variable value in that shell only...I am trying this from last two days...Please mail if u know the answer...
Thanks
 
Michael Morris
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Inderjeet Dhody:
Hello Micheal,
Yeah thats fine..JVM runs in separate shelll...so wat abt if I want to change environment variable value in that shell only...I am trying this from last two days...Please mail if u know the answer...
Thanks

What exactly are you trying to accomplish?
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you're using exec() to run a command, you're hitting a Windows problem common to all languages. The command is executed in a new process, sets the environment in that process, and then the process ends with the command. So the effect of the set is never seen by anyone. Bummer.
If you're trying to run a DOS command that needs some environmetn variables set first, you might put the sets and the command all into a single batch file. That will all run in the same process and should work as long as you don't run out of environment space.
No good:
exec( "set var=value" )
exec( command that looks for var )

Probably good:
exec( batch file that does both )
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic