18 package org.turro.elephant.impl.util;
20 import java.io.BufferedReader;
21 import java.io.IOException;
22 import java.io.InputStream;
23 import java.io.InputStreamReader;
24 import java.util.logging.Level;
25 import java.util.logging.Logger;
26 import org.turro.elephant.context.ElephantContext;
34 class StreamExecutor
extends Thread {
39 StreamExecutor(InputStream is, Level level) {
47 InputStreamReader isr =
new InputStreamReader(is);
48 BufferedReader br =
new BufferedReader(isr);
50 while ((line = br.readLine()) !=
null) {
51 Logger.getLogger(StreamExecutor.class.getName()).log(level, line);
53 }
catch (IOException ioe) {
54 ioe.printStackTrace();
65 String cmd[] =
new String[3];
71 Runtime rt = Runtime.getRuntime();
72 Logger.getLogger(
ShellExecutor.class.getName()).log(Level.INFO,
"Executor: " + command);
74 Process proc = rt.exec(cmd);
76 StreamExecutor errorStream =
new StreamExecutor(proc.getErrorStream(), Level.SEVERE);
78 StreamExecutor outputStream =
new StreamExecutor(proc.getInputStream(), Level.INFO);
83 int exitVal = proc.waitFor();
85 Logger.getLogger(
ShellExecutor.class.getName()).log(Level.INFO,
"Executor exit value for " + command +
": " + exitVal);
89 }
catch (Throwable t) {
static String logMsg(String msg)
int execute(String command)