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:
unable to run 'javac' command thorugh another java file.
Posted by Dhananjay on December 01, 2001 at 11:03 AM
Hi All, I am facing one problem when I am running a 'javac' command through one java program. Please, consider the following 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("Error while compiling"); else System.out.println("Commang get excecuted succesfully"); } } /** * 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". So, I am not able to understand why it is happens. So, if any body have any suggestion/ solution then please let me know as early as possible. Thanks in advance. thanks & regards, Dhananjay Inamdar
Replies:
|