Forums Register Login

Running a java program from within another one

+Pie Number of slices to send: Send
Hi..

Could somebody please tell me how to run a java program from another one when they are in separate packages? The issue is that the java package from which I am trying to access it is not the same as the class file I need to access.

This is the code I am using now :

try{
Runtime runtime = Runtime.getRuntime();
File destDir = new File("/Users/abc/minion/trunk/translator/bin");

String[] args1 =
new String[]{"sh","-c",
"java EssencePrimeTranslator",
"/Users/abc/trans/problems/sokoban/modeltest.cm",
"/Users/abc/trans/problems/sokoban/modeltest.param",
"/Users/abc/trans/problems/sokoban/modeltest.minion"};

runtime.exec(args1,null,destDir);
}
catch(Exception exp){
System.out.println("Exception in run : " + exp.toString());
}

Thanks in advance for the help!!!
+Pie Number of slices to send: Send
Can you bundle everything into a ant script and run the ant script from java application.
+Pie Number of slices to send: Send
Not an advanced question. Moving...

(And "chemical agent" please check your private messages)
+Pie Number of slices to send: Send
Hi Satish,

Thanks for your response. I am not sure of how to go about doing it though, could you please elaborate?
+Pie Number of slices to send: Send
Thanks for your help with this...
The problem is solved. It can be done using the following :

Runtime runtime = Runtime.getRuntime();
String[] args1 = new String[]{
"java","-classpath",
"/Users/abc/minion/trunk/translator/bin","EssencePrimeTranslator",
"/Users/abc/trans/problems/sokoban/modeltest.cm",
"/Users/abc/trans/problems/sokoban/modeltest.param",
"/Users/abc/trans/problems/sokoban/modeltest.minion"};

runtime.exec(args1);
+Pie Number of slices to send: Send
"geetha r"

Your name still does not conform to the JavaRanch Naming Policy. Please review the policy and update it appropriately. This is your second warning.

Scott Selikoff
Hey cool! They got a blimp! But I have a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 926 times.
Similar Threads
String literal Pool doubt
a bug in the Runtime class
Problem in copying directory in Win-NT
java code for running batch file
File.renameTo() Failing On Solaris
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 16:14:49.