This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
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.
 
jQuery in Action, 2nd edition
 
subject: Running DOS commands from java file
 
Similar Threads
how to IO console through MyApplication?
DOS command in java program question..
What's up with this DOS window?
Unix Tutorials
Run dos cmds thru java prg