cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bfede...@apache.org
Subject [04/27] git commit: updated refs/heads/ui-restyle to 205f22b
Date Mon, 07 Oct 2013 18:30:29 GMT
CLOUDSTACK-4813: add function to get ExitValue when run bash commands
(cherry picked from commit b4397acfccd651bc67bb842097def5ded995c125)


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/3a999e70
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/3a999e70
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/3a999e70

Branch: refs/heads/ui-restyle
Commit: 3a999e70af73281a7b682f5c408a036645cd79f6
Parents: 5ed493c
Author: Wei Zhou <w.zhou@leaseweb.com>
Authored: Fri Oct 4 11:05:41 2013 +0200
Committer: Wei Zhou <w.zhou@leaseweb.com>
Committed: Fri Oct 4 11:06:16 2013 +0200

----------------------------------------------------------------------
 utils/src/com/cloud/utils/script/Script.java | 28 ++++++++++++++++++++---
 1 file changed, 25 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3a999e70/utils/src/com/cloud/utils/script/Script.java
----------------------------------------------------------------------
diff --git a/utils/src/com/cloud/utils/script/Script.java b/utils/src/com/cloud/utils/script/Script.java
index 04ad7c4..b84ff2f 100755
--- a/utils/src/com/cloud/utils/script/Script.java
+++ b/utils/src/com/cloud/utils/script/Script.java
@@ -201,8 +201,8 @@ public class Script implements Callable<String> {
                         if (interpreter != null) {
                             return interpreter.drain() ? task.getResult() : interpreter.interpret(ir);
                         } else {
-                            // null return is ok apparently
-                            return (_process.exitValue() == 0) ? "Ok" : "Failed, exit code
" + _process.exitValue();
+                            // null return exitValue apparently
+                            return String.valueOf(_process.exitValue());
                         }
                     } else {
                         break;
@@ -245,7 +245,7 @@ public class Script implements Callable<String> {
                 error = interpreter.processError(reader);
             }
             else {
-                error = "Non zero exit code : " + _process.exitValue();
+                error = String.valueOf(_process.exitValue());
             }
             
             if (_logger.isDebugEnabled()) {
@@ -482,4 +482,26 @@ public class Script implements Callable<String> {
             return result.trim();
     }
 
+    public static int runSimpleBashScriptForExitValue(String command) {
+        return runSimpleBashScriptForExitValue(command, 0);
+    }
+
+    public static int runSimpleBashScriptForExitValue(String command, int timeout) {
+
+        Script s = new Script("/bin/bash", timeout);
+        s.add("-c");
+        s.add(command);
+
+        String result = s.execute(null);
+        if (result == null || result.trim().isEmpty())
+            return -1;
+        else {
+            try {
+                return Integer.valueOf(result.trim());
+            } catch (NumberFormatException e) {
+                return -1;
+            }
+        }
+    }
+
 }


Mime
View raw message