• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Running set variable = value command through Java

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 )
 
I will suppress my every urge. But not this shameless plug:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic