I've a simple program which runs the Dos "dir" command through
java. I can See the output in my java text area but when i run this program on the dos prompt it doesn't show anythin and i have to Cntrl-Alt-Del the programe.
My code isimport java.io.*;
public class toyshell2{
public static void main(
String args[])
{
try{
toyshell2 toy = new toyshell2();
toy.init();
}catch(Exception e){
System.out.println(e);
}
}
public void init() throws Exception{
String commands[]= new String[3];
commands[0]="command.com";
commands[1]="/c";
commands[2]="dir";
Runtime runtime = Runtime.getRuntime();
Process process = runtime.exec(commands);
CheckStream csin = new CheckStream(process.getInputStream());
csin.run();
String line;
int done = process.waitFor();
System.out.println(runtime.freeMemory());
process.destroy();
}
class CheckStream{
BufferedReader br;
String lineread = "";
String lines = "";
String str="";
boolean erroroccured;
CheckStream(InputStream is){
try{
this.br = new BufferedReader(new InputStreamReader(is));
}
catch(Exception e){
System.out.println(e.getMessage());
}
}
/** Reads the input stream and displays anything returned.
*/
public void run(){
try{
while ((lineread = br.readLine()) != null){
System.out.println(lineread);
}
}
catch(Exception e){
System.out.println(e.getMessage());
}
}
}
}