From f8b00bcef004f1bca353cc39621a54e3bfa88f50 Mon Sep 17 00:00:00 2001 From: hrgdavor Date: Fri, 5 Jan 2018 16:02:55 +0100 Subject: [PATCH] extra utils --- src/main/java/hr/hrg/javawatcher/Main.java | 15 ++++++++++++--- src/main/java/hr/hrg/javawatcher/WatchUtil.java | 15 +++++++++++++++ 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/main/java/hr/hrg/javawatcher/Main.java b/src/main/java/hr/hrg/javawatcher/Main.java index 8736b5e..bc35001 100644 --- a/src/main/java/hr/hrg/javawatcher/Main.java +++ b/src/main/java/hr/hrg/javawatcher/Main.java @@ -104,7 +104,7 @@ private static void pipeStream(InputStream inputStream, PrintStream out) throws } - public static void runScript(Logger log, String command, String[] params, Collection changed, boolean postChanges, PrintStream out, PrintStream err) throws Exception{ + public static void runScript(Logger log, String command, String[] params, Collection changed, boolean postChanges, PrintStream out, final PrintStream err) throws Exception{ if(command.startsWith("http://")){ runHttp(log, command, changed, postChanges, out); }else { @@ -118,13 +118,22 @@ public static void runScript(Logger log, String command, String[] params, Collec }else { cmdArray = new String[]{command}; } - Process process = Runtime.getRuntime().exec(cmdArray); + final Process process = Runtime.getRuntime().exec(cmdArray); if(postChanges) { process.getOutputStream().write(bytesToWrite(changed)); process.getOutputStream().close(); } + new Thread(new Runnable() { + public void run() { + try { + pipeStream(process.getErrorStream(), err); + } catch (Exception e) { + e.printStackTrace(); + } + } + }).start(); + pipeStream(process.getInputStream(), out); - pipeStream(process.getErrorStream(), err); log.info("done running script: "+command); } catch (IOException e) { e.printStackTrace(); diff --git a/src/main/java/hr/hrg/javawatcher/WatchUtil.java b/src/main/java/hr/hrg/javawatcher/WatchUtil.java index bb94495..b945634 100644 --- a/src/main/java/hr/hrg/javawatcher/WatchUtil.java +++ b/src/main/java/hr/hrg/javawatcher/WatchUtil.java @@ -11,4 +11,19 @@ public static final boolean classAvailable(String name){ } return false; } + + public static boolean isLinux(){ + String os = System.getProperty("os.name"); + return os.toLowerCase().indexOf("linux") >= 0; + } + + public static String join(String string, String ...params) { + StringBuffer b = new StringBuffer(); + for(int i=0; i 0) b.append(' '); + b.append(params[i]); + } + return b.toString(); + } + }