• 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
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

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

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

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
-----------------------------
 
reply
    Bookmark Topic Watch Topic
  • New Topic