The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
December 2001

Advertisement

Advertisement

This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

Problem while running 'javac' command, through another java file

Posted by Dhananjay Inamdar on December 02, 2001 at 12:03 PM

Hi All,
I am facing one problem when I am running a 'javac' command through one java program.
Please, consider the following sample example to understand my problem.

/**
* This class compiles sample.java
*/
public class test1
{
public static void main(String args[])
{
Runtime a = Runtime.getRuntime();
java.lang.Process P = a.exec("javac sample.java");

System.out.println("After execution of command");

if(P.waitFor()!= 0)
System.out.println("Excecuted succesfully");
else
System.out.println("Error while compiling");

}
}


/**
* This class has to compiled from test1.java
*/
public class sample
{
public static void main(String args[])
{
System.out.println("In the main of sample.java");
}
}

my problem is that in the above mentioned sceanario I get the correct output, but if I purposely make more than 1 error in the sample.java like as follows

/**
* This class has to compiled from test1.java
*/
public class sample
{
public static void main(String args[])
{
System.out.println("In the main of sample.java");
System.out.println(" Value of var1 is :"+ var1); /* error no. 1: var1 is undefined*/
System.out.println(" Value of var2 is :"+ var2); /* error no. 2: var2i is undefined*/
}
}

Now, the execution of test1.java get hanged after printing the statement "After execution of command".
In my actual application I am compiling dynamically generated .java files which may/ may not contain more than 1 error, at that time my application get hanged.
I am not able to understand why it is happens. So, if any body does have any suggestion/ solution then please let me know as early as possible.
Thanks in advance.

thanks & regards,
Dhananjay Inamdar



Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us