wood burning stoves 2.0*
The moose likes Java in General and the fly likes Running DOS commands from java file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Running DOS commands from java file" Watch "Running DOS commands from java file" New topic
Author

Running DOS commands from java file

jvarkha
Greenhorn

Joined: Apr 04, 2000
Posts: 18
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

Joined: Sep 06, 2000
Posts: 51
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

Joined: Apr 04, 2000
Posts: 18
Thanks a lot Apu.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Running DOS commands from java file