aspose file tools*
The moose likes I/O and Streams and the fly likes why can't see the output in dos window after using buffered reader..?? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "why can Watch "why can New topic
Author

why can't see the output in dos window after using buffered reader..??

saurabh panwar
Greenhorn

Joined: Feb 19, 2001
Posts: 5
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());
}
}
}

}
Matt Senecal
Ranch Hand

Joined: Dec 01, 2000
Posts: 255
I sucessfully compiled and ran your code from the DOS prompt. Could you be more specific about the way you're compiling and running? What "java text area" are you using?
This was the output I got in the DOS window:
C:\Files\Matt\Help>java toyshell2
Volume in drive C is Main Gun
Volume Serial Number is FCB4-E423
Directory of C:\FILES\MATT\HELP
. <DIR> 02/20/01 11:25a
.. <DIR> 02/20/01 11:25a
TOYSHE~1 CLA 1202 02/20/01 11:25a
TOYSHE~1 JAV 1162 02/20/01 11:25a
TOYSHE~2 CLA 1191 02/20/01 11:25a
5 file(s) 3555 bytes
1023932928 bytes free
862896


There's nothing more dangerous than a resourceful idiot. ---Dilbert
saurabh panwar
Greenhorn

Joined: Feb 19, 2001
Posts: 5
thanks matt...for carin' to reply...but the prob still persists!!..well i tried something like this.
the output of my dir command is too large and ,may be that's why i 'm not gettin' the output....so i tried to print a large output stored in a text file by my java program(dos command "TYPE") AND TO MU surprise i could only type the file on the dos console when the size of the file was small. I could not type a large file!!!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: why can't see the output in dos window after using buffered reader..??
 
Similar Threads
this code runs in TextPad or Kawa but doesn't run in dos promt..!!!!!
how to execute command in JRun server
how to r.exec("java filename");
exec() in win2000
Compile Java prg within Java prg, show errors