Hi,
I am running the following example given in the java.lang chapter. I
changed the path value in the environment array to something different than
java installed path and still the program ran fine (in eclipse). Not sure
what is the importance of specifying the correct java path. Can someone
please clarify.
import java.io.*;
public class CmdArrayEnv {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Runtime rt = Runtime.getRuntime();
Process proc;
String[] cmdArray = {"javap", "-private", "java.lang.String"};
//Why does the program run successfully even with incorrect path ?
String[] env = {"path=;", "path=d:\\"};
try {
proc = rt.exec(cmdArray,env);
printOutput4Cmd(proc);
}
catch (Exception e) {
System.out.println("Error executing runtime exec");
}
} //main method ends
static void printOutput4Cmd(Process process) {
InputStreamReader isr = new InputStreamReader(new
BufferedInputStream(process.getInputStream()));
BufferedReader br = new BufferedReader(isr);
String line;
while(true) {
try {
line = br.readLine();
if (line == null) {
break;
}
else {
System.out.println(line);
}
}
catch (Exception e) {
System.out.println("readLine Exception");
}
}
} //method ends
}
--
You received this message because you are subscribed to the Google Groups
"JPassion.com: Java Programming" group.
To unsubscribe from this group, send email to
[email protected].
Visit this group at http://groups.google.com/group/jpassion_java?hl=en-US.