From 5d0ce18d812315be3ece9eba45bc3eb2def0cecc Mon Sep 17 00:00:00 2001 From: "Ankur Sinha (Ankur Sinha Gmail)" Date: Wed, 3 Feb 2021 12:32:15 +0000 Subject: [PATCH] Check termination status of graphviz command We now check the error code returned by the command before printing "successfully ran..". If there's an error in the command, because of a malformed dot file for example, we will print the stderr messages for the user and clearly state that the command failed. --- src/main/java/org/neuroml/JNeuroML.java | 29 +++++++++++++++++++------ 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/neuroml/JNeuroML.java b/src/main/java/org/neuroml/JNeuroML.java index 07efe56..444be66 100644 --- a/src/main/java/org/neuroml/JNeuroML.java +++ b/src/main/java/org/neuroml/JNeuroML.java @@ -896,15 +896,30 @@ else if(args[1].equals(GRAPH_FLAG)) { pr.waitFor(); - BufferedReader buf = new BufferedReader(new InputStreamReader(pr.getErrorStream())); - String line; - while((line = buf.readLine()) != null) + /* Successful termination of command */ + if (pr.exitValue() == 0) { - System.out.println("----" + line); + BufferedReader buf = new BufferedReader(new InputStreamReader(pr.getInputStream())); + String line; + while((line = buf.readLine()) != null) + { + System.out.println("----" + line); + } + System.out.println("Have successfully run command: " + cmd); + System.exit(0); + } + /* Unsuccessful termination of command */ + else + { + BufferedReader buf = new BufferedReader(new InputStreamReader(pr.getErrorStream())); + String line; + while((line = buf.readLine()) != null) + { + System.out.println("----" + line); + } + System.out.println("Error running command: " + cmd); + System.exit(1); } - - System.out.println("Have successfully run command: " + cmd); - } catch(InterruptedException e) {