I was able to get the code working with some minor changes I made based on some examples that I found
on this site. I'm not sure why you're getting a IOException.
This was the code that I used with the path modified for my machine:
import java.io.*;
public class Test3 {
public static void main(String[] args) {
Runtime run = Runtime.getRuntime();
try {
Process pp=run.exec("c:\\jdk1.3\\bin\\javac");
BufferedReader in =new BufferedReader(new InputStreamReader(pp.getErrorStream()));
String line;
while ((line = in.readLine()) != null) {
System.out.println(line);
}
int exitVal = pp.waitFor();
System.out.println("Process exitValue: " + exitVal);
} catch (Exception e) {
e.printStackTrace();
System.out.println(e.getMessage());
}
}
}
- import java.io.*;
- public class Test3 {
- public static void main(String[] args) {
- Runtime run = Runtime.getRuntime();
- try {
-
- Process pp=run.exec("c:\\jdk1.3\\bin\\javac");
- BufferedReader in =new BufferedReader(new InputStreamReader(pp.getErrorStream()));
- String line;
- while ((line = in.readLine()) != null) {
- System.out.println(line);
- }
- int exitVal = pp.waitFor();
- System.out.println("Process exitValue: " + exitVal);
- } catch (Exception e) {
- e.printStackTrace();
- System.out.println(e.getMessage());
- }
- }
- }
The output was the same as if I typed it from the command line with the exit value variable added:
Usage: javac <options> <source files>
where possible options include:
-g Generate all debugging info
-g:none Generate no debugging info
-g:{lines,vars,source} Generate only some debugging info
-O Optimize; may hinder debugging or enlarge class file
-nowarn Generate no warnings
-verbose Output messages about what the compiler is doing
-deprecation Output source locations where deprecated APIs are us
ed
-classpath <path> Specify where to find user class files
-sourcepath <path> Specify where to find input source files
-bootclasspath <path> Override location of bootstrap class files
-extdirs <dirs> Override location of installed extensions
-d <directory> Specify where to place generated class files
-encoding <encoding> Specify character encoding used by source files
-target <release> Generate class files for specific VM version
Process exitValue: 2
- Usage: javac <options> <source files>
- where possible options include:
- -g Generate all debugging info
- -g:none Generate no debugging info
- -g:{lines,vars,source} Generate only some debugging info
- -O Optimize; may hinder debugging or enlarge class file
- -nowarn Generate no warnings
- -verbose Output messages about what the compiler is doing
- -deprecation Output source locations where deprecated APIs are us
- ed
- -classpath <path> Specify where to find user class files
- -sourcepath <path> Specify where to find input source files
- -bootclasspath <path> Override location of bootstrap class files
- -extdirs <dirs> Override location of installed extensions
- -d <directory> Specify where to place generated class files
- -encoding <encoding> Specify character encoding used by source files
- -target <release> Generate class files for specific VM version
- Process exitValue: 2
Free Programming Resources