Reputation: 377
I am making a program that needs some of the Java libraries installed already into the computer and also the "classpath" environment variable to be set.
I want to run the set classpath command. Can I do it through java? Or do I need to do something else? Any Example?
Upvotes: 0
Views: 149
Reputation: 2275
Something like
public static void main(String[] args)
{
try
{
if (args == null || (args != null && args.length != 1))
{
System.out.println("Please provide a command");
}
Runtime.getRuntime().exec(args);
}
catch (Exception ex)
{
ex.printStackTrace();
}
}
Upvotes: 2
Reputation: 308733
Yes, you can. Here's are some examples to show you how to do it:
http://www.javaworld.com/jw-12-2000/jw-1229-traps.html
http://www.ehow.com/way_5660016_java-runtime-exec-tutorial.html
Upvotes: 2
Reputation: 69663
set.exe
is a program like any other. You can start it with Runtime.exec().
Upvotes: 1
Reputation: 1759
If you want to set a system property, you can use System.setProperty(key,value).
Upvotes: 2