Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Running DOS commands from java file

 
jvarkha
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI,
I have a Java program that reads a text file. This file contains a method signature on every line, basically either get or set methods. The program sorts the source file and writes all the get methods into one text file, and the set methods into another text file. Now I want the java program to be able to show the contents of both these files, just as we would type "type get.txt" on the DOS command line. We can write the contents of these files using output streams onto the console, but can we run the DOS commands from the java file itself ?
Any suggestions would be welcome.
Thanks in advance.
 
Apu Nahasapeemapetilon
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Process P;
Runtime rt = Runtime.getRuntime();
P = rt.exec("type get.txt");
One can then use a buffered reader to get the process output if one desires.
 
jvarkha
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot Apu.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic