aspose file tools*
The moose likes Beginning Java and the fly likes Running Programs from JAVA Programs Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Running Programs from JAVA Programs" Watch "Running Programs from JAVA Programs" New topic
Author

Running Programs from JAVA Programs

Parth Sagdeo
Ranch Hand

Joined: Mar 18, 2004
Posts: 40
Hi all,
How would one run another program from a JAVA program. For example, how would one code a program open a web browser or compile another JAVA file?
Sincerely,
Parth
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
The short answer to this question is that you use the command:

Runtime.getRuntime().exec("javac MyClass.java");

However there are some pitfalls and things to be aware of in running this. Here's a link to an article that explains some of them:

http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html

Good Luck.

Merrill


Merrill
Consultant, Sima Solutions
Surasak Leenapongpanit
Ranch Hand

Joined: May 10, 2002
Posts: 341
If you want to compile the other classes at runtime, see Compiler class in Java API.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Running Programs from JAVA Programs