Make sure we read stdout/err when exec is used (FELIX-1297).
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@809945 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/framework/src/main/java/org/apache/felix/framework/cache/JarContent.java b/framework/src/main/java/org/apache/felix/framework/cache/JarContent.java
index 1be5d99..29e1f19 100644
--- a/framework/src/main/java/org/apache/felix/framework/cache/JarContent.java
+++ b/framework/src/main/java/org/apache/felix/framework/cache/JarContent.java
@@ -23,6 +23,7 @@
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
+import java.io.OutputStream;
import java.util.Enumeration;
import java.util.Map;
import java.util.Properties;
@@ -373,7 +374,17 @@
props.setProperty("abspath", libFile.toString());
command = Util.substVars(command, "command", null, props);
Process p = BundleCache.getSecureAction().exec(command);
+ // We have to make sure we read stdout and stderr because otherwise
+ // we will block on certain unbuffered os's (like eg. windows)
+ Thread stdOut = new Thread(new DevNullRunnable(p.getInputStream()));
+ Thread stdErr = new Thread(new DevNullRunnable(p.getErrorStream()));
+ stdOut.setDaemon(true);
+ stdErr.setDaemon(true);
+ stdOut.start();
+ stdErr.start();
p.waitFor();
+ stdOut.join();
+ stdErr.join();
}
// Return the path to the extracted native library.
@@ -517,4 +528,33 @@
return ((ZipEntry) m_enumeration.nextElement()).getName();
}
}
+
+ private static class DevNullRunnable implements Runnable
+ {
+ private final InputStream m_in;
+
+ public DevNullRunnable(InputStream in)
+ {
+ m_in = in;
+ }
+
+ public void run()
+ {
+ try
+ {
+ try
+ {
+ while (m_in.read() != -1){}
+ }
+ finally
+ {
+ m_in.close();
+ }
+ }
+ catch (Exception ex)
+ {
+ // Not much we can do - maybe we should log it?
+ }
+ }
+ }
}
\ No newline at end of file