reintroduced StringUtil.regexpReplace
[mir.git] / source / mir / util / ShellRoutines.java
index 4dbd67a..fc12d7d 100644 (file)
@@ -62,25 +62,29 @@ public class ShellRoutines {
    */
   public static byte[] execIntoByteArray(String command) throws IOException {
     File commandOutput = File.createTempFile("mircmd", "");
-    int exitStatus;
     try {
-      // WARNING: unix specific
-      exitStatus = Runtime.getRuntime().exec(new String[]{
-        "/bin/sh", "-c",
-        command + " " +
-          ">" + commandOutput.getAbsolutePath()
-      }).waitFor();
-    }
-    catch (InterruptedException e) {
-      throw new IOException(e.toString());
+      int exitStatus;
+      try {
+        // WARNING: unix specific
+
+        exitStatus = Runtime.getRuntime().exec(new String[]{
+          "/bin/sh", "-c",
+          command + " " +
+            ">" + commandOutput.getAbsolutePath()
+        }).waitFor();
+      }
+      catch (InterruptedException e) {
+        throw new IOException(e.toString());
+      }
+      if (exitStatus != 0) {
+        throw new IOException("command exit satus:" + exitStatus);
+      }
+      return FileRoutines.readFileIntoByteArray
+          (commandOutput.getAbsoluteFile());
     }
-    if (exitStatus != 0) {
-      throw new IOException("command exit satus:" + exitStatus);
+    finally {
+      commandOutput.delete();
     }
-    byte[] result = FileRoutines.readFileIntoByteArray
-        (commandOutput.getAbsoluteFile());
-    commandOutput.delete();
-    return result;
   }
 
   /**
@@ -97,7 +101,9 @@ public class ShellRoutines {
                "/bin/sh", "-c", command
       });
       Reader errorStreamReader = new InputStreamReader(process.getErrorStream());
-      ReaderLogger logger = new ReaderLogger(errorStreamReader, new LoggerWrapper("Utility"));
+      ReaderLogger logger =
+          new ReaderLogger(errorStreamReader, new LoggerWrapper("Utility"));
+
       new Thread(logger).start();
 
       Reader outputStreamReader = new InputStreamReader(process.getInputStream());
@@ -134,6 +140,7 @@ public class ShellRoutines {
       }
       catch (IOException e) {
       }
+
       writer.close();
       try {
         reader.close();