• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Running DOS commands from java file

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot Apu.
 
reply
    Bookmark Topic Watch Topic
  • New Topic