function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
NashornNashorn 

detecting connection errors when running the DataLoader as an external process from Java

I am writing an application that calls the DataLoader as an external Java process. For example:

String str="java -jar -Dsalesforce.config.dir=C:/dataloader/ C:\bin\sforcedataloader.jar";
Process p = Runtime.getRuntime().exec(str);
p.waitFor();

I have two related problems regarding error handling.

1) Sometimes when the DataLoader has a problem connecting to the salesforce.com service the exec() method doesn't return, and my program runs indefinitely (wheareas if you run the DataLoader from the command line and it has a problem connecting then you simply get another input prompt after the error message has been displayed in the log4j output and the DataLoader then stops running).

The Process class doesn't seem to give much feedback as to what is going on with a running process. Does anyone know how I can stop my program from hanging when the DataLoader has such a connection error?

2) At least I can parse through the log4j output that the DataLoader produces. Maybe the solution to the previous question is simply something like:

BufferedReader stdOutput = new BufferedReader(new InputStreamReader(p.getInputStream()));
            
String str = "";

System.out.println("DataLoader standard output:\n");
while ((str = stdOutput.readLine()) != null) {
    System.out.println(str);
    //parse string and decide if something needs to be done
    //if determine for instance that the connection failed, call p.destroy() and then let my java program continue executing
}

My question in this case is, what exactly do I need to search for in this string for in order to gracefully handle the errors that are returned by the DataLoader? Some DataLoader errors will be ok, such as when a record is updated with a value that is the wrong data type. However, I want to single out all fatal errors, such as a connection problem.

Any hints as to how I can get a list of what exceptions/errors that I need to watch for would be appreciated!