Solved

executing set command

Posted on 2002-05-14
10
193 Views
Last Modified: 2011-09-20
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.
0
Comment
Question by:BabyFace
  • 4
  • 3
  • 3
10 Comments
 
LVL 4

Expert Comment

by:antons061400
ID: 7010391
please send the commnad you tried. It should be something like

"cmd /C set var=xxx"
0
 
LVL 1

Author Comment

by:BabyFace
ID: 7011451
"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
0
 
LVL 92

Expert Comment

by:objects
ID: 7012676
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.
0
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 
LVL 1

Author Comment

by:BabyFace
ID: 7013639
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...
0
 
LVL 4

Expert Comment

by:antons061400
ID: 7013667
problem is that the 'cmd /C set ...' starts new shell (cmd)
0
 
LVL 1

Author Comment

by:BabyFace
ID: 7013689
can you suggest a work around?
0
 
LVL 4

Accepted Solution

by:
antons061400 earned 100 total points
ID: 7013722
I think you must redesign this use case.

as I understand you want to start java application to set some env and then you want to start something else.

So you can :
- start 'something else' directly from java together with setting ...
- the java will create some batch file, which will be executed before 'something else' (this can be combinated with first point.)

there is also one terrible way, how to get information from runing program to the starting shell using FOR /F command - but it is really stupid
0
 
LVL 92

Expert Comment

by:objects
ID: 7014993
> 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?
0
 
LVL 1

Author Comment

by:BabyFace
ID: 7015206
It's ok.
I guess i'll use batch files or something.
Thanks anyway.
0
 
LVL 92

Expert Comment

by:objects
ID: 7015222
How does using a batch file affect the env of the current DOS window?
0

Featured Post

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
thymeleaf natural templating vs JSP 2 103
why cannot we forward request once the response is committed 2 42
factorial example 4 40
SHA2 certs for IIS AND Java? 2 93
For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question