1

For examples, this is my bash script

osascript -e 'tell app "Terminal"
 do script "./process1"
end tell'

osascript -e 'tell app "Terminal"
 do script "./process2"
end tell'

Basically, it will open two different terminal windows (on mac) and execute defined commands. I try to do this in java by

process1 = Runtime.getRuntime().exec(new String[]{"process1"});
process2 = Runtime.getRuntime().exec(new String[]{"process2"});

The problem is it seems that there is only one terminal is opened (and not visible - it runs in background) and then two command process1 and process2 are executed. But because the process 1 will keep that terminal busy thus process2 cannot run. That's why I want to open different terminal to execute those commands.

Xitrum
  • 7,765
  • 26
  • 90
  • 126
  • You could always create a thread for each process. Then you can what until process1 is complete before starting process2 – Franklin Mar 22 '13 at 14:38
  • I did try to wrap them in different Threads, then execute each thread, but there was no successful – Xitrum Mar 22 '13 at 14:39
  • Have you tried with ProcessBuilder instead of Runtime ? You might need to redirect standard input, output and error also to make the new process independent of the JVM process. – Benoit Thiery Mar 22 '13 at 14:45
  • I will try it, but i dont think they are different – Xitrum Mar 22 '13 at 14:49
  • Could you post your threading code? – Franklin Mar 22 '13 at 14:50
  • basically i wrap each process in this Thread thread = new Thread(){ public void run(){ System.out.println("Thread Running"); } } thread.start(); – Xitrum Mar 22 '13 at 14:55
  • but then do you wait for the the first thread to stop? http://stackoverflow.com/questions/1361029/waiting-on-multiple-threads-to-complete-in-java – Franklin Mar 22 '13 at 14:56
  • if the first thread stop , will the process 1 will also be killed ? that's what i dont want... – Xitrum Mar 22 '13 at 14:57
  • basically, what i did was thread1.start() then thread2.start() – Xitrum Mar 22 '13 at 14:59

1 Answers1

0

Create a thread for each one of them. and give a time space "sleep(for some time thread 1 or 2)" and this will run both depending on you operating system.