Solved

executing set command

Posted on 2002-05-14
10
177 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
Comment Utility
please send the commnad you tried. It should be something like

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

Author Comment

by:BabyFace
Comment Utility
"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
Comment Utility
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
 
LVL 1

Author Comment

by:BabyFace
Comment Utility
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
Comment Utility
problem is that the 'cmd /C set ...' starts new shell (cmd)
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 1

Author Comment

by:BabyFace
Comment Utility
can you suggest a work around?
0
 
LVL 4

Accepted Solution

by:
antons061400 earned 100 total points
Comment Utility
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
Comment Utility
> 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
Comment Utility
It's ok.
I guess i'll use batch files or something.
Thanks anyway.
0
 
LVL 92

Expert Comment

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

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
hash value 2 38
countX 22 67
java set up 1 44
Java. Convert method from recursion based to iteration based ( loop based ) 6 43
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

728 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now