This week's book giveaway is in the Spring forum.
We're giving away four copies of Spring Boot in Practice and have Somnath Musib on-line!
See this thread for details.
Win a copy of Spring Boot in Practice this week in the Spring forum!
  • 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
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

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
-----------------------------
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic