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 Beginning Java and the fly likes run a run command 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 » Beginning Java
Bookmark "run a run command" Watch "run a run command" New topic

run a run command

ramesh kancherla
Ranch Hand

Joined: May 01, 2008
Posts: 124
how to run a run command in java

i want compile and execute a java program with other java program.
how is it possible can you give me example
Edwin Dalorzo
Ranch Hand

Joined: Dec 31, 2004
Posts: 961
What do you mean by a run command?

If what you have is a jar file containing another application. You can simply add that jar to your class path and invoke the method you want to run.

If what you want is to invoke the java launcher command as you would do from the command line, well then you can use the java.lang.ProcessBuilder to build the command and then invoke it.
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63874

Please take the time to choose the correct forum for your posts. This forum is for questions on I/O.

This post has been moved to a more appropriate forum.

[Asking smart questions] [About Bear] [Books by Bear]
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 46437
You will need to use a ProcessBuilder to create a Process object, or the older method using Runtime.exec().
When you start a Process there are two Streams; I think they represent standard output and standard error, but am not sure, and you have to keep them "empty" by reading their contents as fast as they are filled.
You also have to wait for the Process to finish before using its results.
You can find details by searching the forum for similar posts; here is one from last year.

Note my quote of DaConta's classic article from 8 years ago. Note that ProcessBuilder was not available then.

I hope that gives you a hint where to start.
I agree. Here's the link:
subject: run a run command
It's not a secret anymore!