*
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 Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "run a run command" Watch "run a run command" New topic
Author

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
Marshal

Joined: Jan 10, 2002
Posts: 60741
    
  65

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] [Bear's FrontMan] [About Bear] [Books by Bear]
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37897
    
  22
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: http://aspose.com/file-tools
 
subject: run a run command
 
Similar Threads
run Dos commands in java app
System commands
System commands
javax/mail/Message error
How to run dos batch file from java program