This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
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 Java Interview Guide 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: 13037
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()
It's not a secret anymore!