I want my java program to execute a different java program. I used following method.
(The program I want to run is Example.java)
class RunJava
{
public static void main(String a[])throws Exception
{
Runtime.getRunTime().exec("c:\\"+path+"\\javac Example.java");
Runtime.getRunTime().exec("c:\\"+path+"\\java Example");
}
But it is not working. Is there any other way of doing this?
javacshould be the first.. before that path (andjavatoo).main(String[]).. Read (and implement) all the recommendations of When Runtime.exec() won't. That might solve the problem. If not, it should provide more information as to the reason it failed. Then ignore that it refers toexecand build theProcessusing aProcessBuilder. Also break aString argintoString[] argsto account for arguments which themselves contain spaces.