Solved

executing set command

Posted on 2002-05-14
10
209 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
throw exception 21 76
JavaFX TableView not displaying correctly 3 152
String array comparison 4 56
Selenium docs api java index 3 96
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…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Suggested Courses

737 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