[Schmitzm-commits] r2319 - trunk/schmitzm-core/src/main/java/de/schmitzm/io

scm-commit at wald.intevation.org scm-commit at wald.intevation.org
Fri May 31 17:55:37 CEST 2013


Author: mojays
Date: 2013-05-31 17:55:37 +0200 (Fri, 31 May 2013)
New Revision: 2319

Modified:
   trunk/schmitzm-core/src/main/java/de/schmitzm/io/IOUtil.java
Log:
IOUtil: new method to exec a shell script

Modified: trunk/schmitzm-core/src/main/java/de/schmitzm/io/IOUtil.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/io/IOUtil.java	2013-05-27 15:24:35 UTC (rev 2318)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/io/IOUtil.java	2013-05-31 15:55:37 UTC (rev 2319)
@@ -64,6 +64,7 @@
 import java.security.MessageDigest;
 import java.security.NoSuchAlgorithmException;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collection;
 import java.util.Enumeration;
 import java.util.List;
@@ -2916,4 +2917,29 @@
 //      LOGGER.debug("Start command: "+startCommand);
 	  return startCommand;
 	}
+	
+	/**
+	 * Executes a (shell) script (see {@link Runtime#exec(String[])}) and returns
+	 * the process output as string.
+	 */
+	public static String exec(String... script) throws IOException {
+	  Process process= Runtime.getRuntime().exec(script);
+	  String output = convertStreamToString(process.getInputStream());
+	  return output;
+	  
+//      String APP_SERVICE_NAME = "postgresql-x64-9.1";
+//      String SERVICE_NAME = "postgresql-x64-9.1";
+//      String[] scriptCheck = {"cmd.exe", "/c", "sc", "query", APP_SERVICE_NAME, "|", "find", "/C", "\"RUNNING\""};//to check whether service is running or not
+//
+//      String[] scriptStart = {"cmd.exe", "/c", "sc", "start", SERVICE_NAME};//to start service
+//
+//      String[] scriptStop = {"cmd.exe", "/c", "sc", "stop", SERVICE_NAME};//to stop service
+//      String  res = IOUtil.exec(scriptCheck);
+//      System.out.println(res);
+//      if ( "0".equals(res.trim()) ) {
+//        res = IOUtil.exec(scriptStart);
+//        System.out.println(res);
+//      }
+	  
+	}	
 }



More information about the Schmitzm-commits mailing list