Skip to content

Commit

Permalink
extra utils
Browse files Browse the repository at this point in the history
  • Loading branch information
hrgdavor committed Jan 5, 2018
1 parent fbbc56a commit f8b00bc
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/main/java/hr/hrg/javawatcher/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ private static void pipeStream(InputStream inputStream, PrintStream out) throws

}

public static void runScript(Logger log, String command, String[] params, Collection<Path> changed, boolean postChanges, PrintStream out, PrintStream err) throws Exception{
public static void runScript(Logger log, String command, String[] params, Collection<Path> changed, boolean postChanges, PrintStream out, final PrintStream err) throws Exception{
if(command.startsWith("http://")){
runHttp(log, command, changed, postChanges, out);
}else {
Expand All @@ -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();
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/hr/hrg/javawatcher/WatchUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<params.length; i++){
if(i > 0) b.append(' ');
b.append(params[i]);
}
return b.toString();
}

}

0 comments on commit f8b00bc

Please sign in to comment.