Solved

executing set command

Posted on 2002-05-14
10
201 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
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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.

 
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
servlet example 17 53
null output 3 36
Eclipse Java import and method not resolved 4 52
swing controls 2 16
For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …

821 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