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 Running set  variable = value command through Java 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 "Running set  variable = value command through Java " Watch "Running set  variable = value command through Java " New topic
Author

Running set variable = value command through Java

Inderjeet Dhody
Greenhorn

Joined: Jul 04, 2003
Posts: 4
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

Joined: Jan 30, 2002
Posts: 3451
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.


Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
Inderjeet Dhody
Greenhorn

Joined: Jul 04, 2003
Posts: 4
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

Joined: Jan 30, 2002
Posts: 3451
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

Joined: Jan 29, 2003
Posts: 8791
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 )


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Running set variable = value command through Java
 
Similar Threads
Java Runtime Error
'javac' is not recognized as ...
getting and setting environment variables
What are class path variable ?
Java