How to use exec() twice?

Hi,

I'd like to invoke two execution files with the command, exec(), but it's not working correctly. For example, I'd like to execute a1.exe and a2.exe at the same time, but the second one is not executed.

public class Hello {

public static void main(String argv[]) throws IOException {

Process p = Runtime.getRuntime().exec("c:\\a1.exe");

p = Runtime.getRuntime().exec("c:\\a2.exe

");

}

}

What's the problem of it? Is there any solution for it? I appreciate your help.

Thanks.

- Won

[574 byte] By [wonjeon] at [2007-9-26 4:22:03]
# 1
Maybe you have to use Threads(it is just an idea)
MadBull at 2007-6-29 17:26:49 > top of Java-index,Desktop,Runtime Environment...
# 2
you'll have to start two different processes then! try p1 and p2 ;-)
RiGe at 2007-6-29 17:26:49 > top of Java-index,Desktop,Runtime Environment...
# 3
>to start two different processes then! try p1 and p2 The code is starting two processes.
jschell at 2007-6-29 17:26:49 > top of Java-index,Desktop,Runtime Environment...
# 4
>but the second one is not executed.And you know this how?Presumably the second does not depend on the first?
jschell at 2007-6-29 17:26:49 > top of Java-index,Desktop,Runtime Environment...
# 5

I would agree with RiGe it is better to create separate references to the instances like p1, p2. The process gives you control over the i/o streams, i mean to the parent process. But nothing stops the sub-process from executing even if all references are removed. Well the behavior of Runtime is not guaranteed in the native window platform...

vinfra at 2007-6-29 17:26:49 > top of Java-index,Desktop,Runtime Environment...
# 6
why don't u issu waitFor() after first call to exec..and let the first execution finish of. hope this helps.
sultan2001 at 2007-6-29 17:26:49 > top of Java-index,Desktop,Runtime Environment...