I basically want to write a simple GUI program to sync to directories using the rsync
command. The core part of the code is below. My main question is, do I need to have the waitFor
method included? At present, I have left it out, because I would like to show the user the --progress
responses as it would in terminal, not wait until the end. Is this a bad idea?
public void executeCommand(String src, String dest) {
System.out.println("Starting shell");
Process p;
try {
System.out.println("Creating process...");
p = Runtime.getRuntime().exec("rsync --progress -va "+src +" "+ dest );
//p.waitFor(); <- is this important?
System.out.println("Creating reader...");
BufferedReader reader =
new BufferedReader(new InputStreamReader(p.getInputStream()));
String line = "";
System.out.println("Starting sync...");
while ((line = reader.readLine())!= null) {
System.out.println(line);
textAreaAppend(line);
}
} catch (Exception e) {
e.printStackTrace();
}
}
public void textAreaAppend(String line){
textArea.append(line +"\n");
}