Hi All,
I wonder if anyone could help?
I have a large Java program which needs at various points to run UNIX commands. The only wayI have found to do this is below (although I would have liked the program to output all terminal commands into the same window (shell) as the program is loaded in) - this code launches new shells silently in the background.
The problem I have is that the code, launches this command and immediately continues to the next lines of code (it doesn't wait for this command to execute and complete before continuing). Due to times varying between folders (due to contents, processing speeds etc) it would be ineffective and inefficient for me to use set wait times.
Does anyone know how to make the program wait for this command to complete before it moves onto the next lines of code?
Thank you very much for your time and help,
Tango2010
Please see code attached:
try {
System.out.println("Copying files using UNIX file system");
String[] unixcopy = {"/bin/sh", "-c", "sudo cp -R " + "/filea/ " + "/fileb/"};
Process punixcopy = Runtime.getRuntime().exec(unixcopy);
}
catch (Throwable t)
{
t.printStackTrace();
}