• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

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

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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());
}
}
}

}
 
Ranch Hand
Posts: 255
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
saurabh panwar
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!!!
 
What are your superhero powers? Go ahead and try them on this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic