Permalink
Browse files

[postgresql] fixed extraction of exit status

  • Loading branch information...
1 parent 27dc9e4 commit c5867d15a6029ba515dd29dde7f7687ea8d1a44e Schakko committed Feb 22, 2013
@@ -49,7 +49,7 @@ class DBInterface {
throw new Exception("Could not filter output")
}
- if (e.getMessage().split("\n")[0].matches(/(.*)relation(.*)does not exist/)) {
+ if (e.getMessage().split("\n")[0].matches(/(.*)[Rr]elation(.*)migration(.*)/)) {
println "[create] trying to create migration table ..."
try {
@@ -64,35 +64,38 @@ class Executor {
def joinedCommand = cmd.join(" ")
def processBuilder = (System.getProperty("os.name").toLowerCase().contains("win")) ? new ProcessBuilder(joinedCommand) : new ProcessBuilder("sh", "-c", joinedCommand)
- processBuilder.redirectErrorStream(true);
-
// sending the password through a stream does not work because of some weird reasons
// we have to set the environment variable PGPASSWORD (as described in man page) to pass the password to the SQL command
if (password) {
processBuilder.environment().put("PGPASSWORD", password)
}
- def proc = null, text = "", err = ""
+ processBuilder.environment().put("ON_ERROR_STOP", "1")
+ processBuilder.redirectErrorStream(true)
+
+ def proc = null, text = "", err = ""
+
try {
proc = processBuilder.start()
+ proc.waitFor()
text = proc.text
err = proc.err.text
- proc.waitFor()
-
- if (proc.exitValue()) {
- throw new Exception("Wrong exit value from command")
- }
}
catch (Exception e) {
- if (err)
- throw new Exception(e.getMessage() + ": " + err)
- else
- throw new Exception(e.getMessage() + ": Command did not exit normal but although did not return any error text. Is the executed command correct? Normal text stream follows:\n" + text)
+ println joinedCommand + " exits with value: " + proc.exitValue()
+
+ if (proc.exitValue() > 0) {
+ if (err)
+ throw new Exception(e.getMessage() + ": " + err)
+ else
+ throw new Exception(e.getMessage() + ": Command did not exit normal but although did not return any error text. Is the executed command correct? Normal text stream follows:" + text)
+ }
}
return text
}
+
/**
* Executes a single command

0 comments on commit c5867d1

Please sign in to comment.