Executing another program in Java

Hi,

Im trying to run a java application from inside another one. After reading up about it on these forums, as well as some other places, I tried out example code from these forums. All I do at the moment is run a java class called Hello. This class just has a main method that Prints out "Hello world."

I can get this to run in the example, but I cant get the Hello program to display its output.

If I do this:

proc1 = Runtime.getRuntime().exec("java c:\\Java\\Hello");

then I get absolutely no output. I tried putting "java c:\java\Hello" inside a .bat file, and I output from the batch file, but not from my java program.

out :

out :C:\Java\executeprocess>java Hello

Here is a snip of the code, without the main method, variables, and so on.

try{

proc1 = Runtime.getRuntime().exec("c:\\java\\Test.bat");

input = proc1.getInputStream();

in =new BufferedReader(new InputStreamReader(input));

err =new BufferedReader(new InputStreamReader(input));

out =new PrintWriter(proc1.getOutputStream());

}catch (Exception e1){

e1.printStackTrace();

}

String line ="";

while ((line=in.readLine()) !=null){

System.out.println("out: " + line);

}

Any ideas what the problem might be?

On a side note, I know I could just run the main method of this class in my java program, but I dont have the source of the class I want to run. I also want to run the class with some parameters similar to the following example(its a Jini class server) and get the output from it in my java program. Is this possible?

java -classpath <<insert classpath>> -jar .\lib\tools.jar -port 8081 -dir .\lib -verbose

[2307 byte] By [ChrisTylera] at [2007-11-26 12:22:27]
# 1
Use Reflections.please read. http://java.sun.com/docs/books/tutorial/reflect/index.html=)
Redxxiva at 2007-7-7 15:15:46 > top of Java-index,Archived Forums,Socket Programming...
# 2
http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html
camickra at 2007-7-7 15:15:46 > top of Java-index,Archived Forums,Socket Programming...