File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes exec() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "exec()" Watch "exec()" New topic


Sandeep Advani
Ranch Hand

Joined: Mar 11, 2004
Posts: 78
Can I compile a .java file using Runtime.getRuntime().exec("javac")? If not, is it possible to do the same?

William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 12835
It is a bit more complicated than that - you have to consume the stdout and stderr character streams. Read the java.lang.Process JavaDocs.
The use of exec comes up frequently - search the ranch archives.
Stefan Wagner
Ranch Hand

Joined: Jun 02, 2003
Posts: 1923

Or put tools.jar into your classpath, and use the Compiler.class inside.
I agree. Here's the link:
subject: exec()