• Post Reply Bookmark Topic Watch Topic
  • New Topic

this code runs in TextPad or Kawa but doesn't run in dos promt..!!!!!  RSS feed

 
saurabh panwar
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
import java.io.*;
//import java.lang.*;
//import java.util.*;
//import java.math.*;
//import java.util.*;
public class toyshell{

public static void main(String args[])
{
try{
toyshell toy = new toyshell();
String command ="dir";
String commands[]= new String[3];

//if(command.length()==0)
//{
//System.out.println("bad command");

//}
//else
//{

//System.out.println(command);
//}



if (command.equalsIgnoreCase("dir"))
{
System.out.println("command dir");

commands[0]="command.com";
commands[1]="/c";
commands[2]="dir";

Runtime runtime = Runtime.getRuntime();
Process process = runtime.exec(commands);


BufferedReader reader = new BufferedReader(new InputStreamReader(new DataInputStream( new BufferedInputStream(process.getInputStream()))));
String lineRead =null;

while( (lineRead = reader.readLine() ) != null)
{
System.out.println("hello");
String abc;
abc=lineRead;
//System.out.println(lineRead);
System.out.println(abc);

}

int done = process.waitFor();
System.out.println(done);


process.destroy();

}





}catch(Exception e){System.out.println(e);}
}
}

 
ming fan
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, I have tried your code, and it works fine on my NT dos prompt. Which dos prompt are you using? Check the Process javadoc, it says the following:
The Runtime.exec methods may not work well for special processes on certain native platforms, such as native windowing processes, daemon processes, Win16/DOS processes on Win32, or shell scripts.
If you are running win16/dos processes on win32, then that could give you some problem. Hope this helps.

Ming Fan
-----------------------------
Sun Certified Java Programmer
-----------------------------
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!