?
Solved

executing set command

Posted on 2002-05-14
10
Medium Priority
?
215 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
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 
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 400 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

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

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

Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
In this post we will learn different types of Android Layout and some basics of an Android App.
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…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses
Course of the Month10 days, 11 hours left to enroll

765 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