Link to home
Start Free TrialLog in
Avatar of BabyFace
BabyFace

asked on

executing set command

Hi,
I'm using windows and would like to set some environment variables from my java program via the set command. The only problem is that I don't know how to invoke it directly from my program. I've look at the exec method of the Runtime class but it failed to create the process. I do not wan't to call a batch file to run the set command.

Thanks.
Avatar of antons061400
antons061400

please send the commnad you tried. It should be something like

"cmd /C set var=xxx"
Avatar of BabyFace

ASKER

"cmd /C set classpath=ccc"
when this command is executed through the Runtime instance I don't see it in the environment when I type:
set c

Thanks
Avatar of Mick Barry
Calling set only changes the environment for that shell instance. To demonstrate this, open two DOS windows and set an environment var in one. Then check the env in the other and you'll see it's not set there. And even if you open a new DOS window it won't be set there either.
I don't know of a way to do what you require.
Clarification:
I only require that the environment variable be set in the instance of the DOS window where the class file was ran.
When I open a new DOS window, then run my program (it tell the Runtime to execute something like "cmd /C set classpath=ccc".) The env. var. are not set...
problem is that the 'cmd /C set ...' starts new shell (cmd)
can you suggest a work around?
ASKER CERTIFIED SOLUTION
Avatar of antons061400
antons061400

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
> I only require that the environment variable be set in
> the instance of the DOS window where the class
> file was ran.

Don't know of any way to do that.
What exactly is it you are trying to do?
It's ok.
I guess i'll use batch files or something.
Thanks anyway.
How does using a batch file affect the env of the current DOS window?