This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes running a java program Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "running a java program" Watch "running a java program" New topic
Author

running a java program

Prahlad Joshi
Ranch Hand

Joined: Apr 21, 2007
Posts: 44
i want to run a package containing .class files from a java program for this i have written:
Process tempProcess=Runtime.getRuntime().exec("java "+ mainClassName,null,new java.io.File(absolutePackagePath));
tempProcess.waitFor();
but the problem is that i am not able to given input to this tempProcess or see output of it.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39577
    
  27
That code may produce some output or need some input that your code isn't handling. See this article for pitfalls to avoid when using Runtime.exec.


Ping & DNS - updated with new look and Ping home screen widget
Kelvin Chenhao Lim
Ranch Hand

Joined: Oct 20, 2007
Posts: 513
Aside from the issues that Ulf pointed out, are you also sure you want to start a new JVM to run your sub-application? Depending on exactly what you want to achieve, you may find the Reflection API more useful and appropriate. Things get slightly complicated if the .class files aren't already in your current classpath (you may need to create a new class loader), but this may still be better than using Runtime.exec().


SCJP 5.0
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: running a java program
 
Similar Threads
Mainframe client
Real World Java Code
What Java book to get for a beginner?
Why main is declared as static?
Dx Ball Game