Permalink
Browse files

Fixed a little bug with redirecting stdout.

  • Loading branch information...
1 parent c7cbfeb commit c75264e08060669b987861fd9b5b11ba31273855 @jbrisbin committed with Oct 16, 2011
Showing with 15 additions and 9 deletions.
  1. +1 −1 bin/mqdsl.bat
  2. +14 −8 src/main/java/com/jbrisbin/groovy/mqdsl/RabbitMQDsl.java
View
@@ -1,7 +1,7 @@
@echo off
setlocal enabledelayedexpansion
-set CP=%~dp0\conf
+set CP=%~dp0..\conf
rem Add all jars in "lib" to CLASSPATH
for %%j in ("%~dp0..\lib\*.jar") do set CP=!CP!%%~fj;
rem Add packaged jar
@@ -24,6 +24,7 @@
import java.io.FileOutputStream;
import java.io.FilenameFilter;
import java.io.IOException;
+import java.io.PrintStream;
import java.util.Properties;
import groovy.lang.Binding;
@@ -119,15 +120,15 @@ public static void main(String[] argv) {
System.err.println("No script file to evaluate...");
}
- BufferedOutputStream out = null;
+ PrintStream stdout = System.out;
+ PrintStream out = null;
if (args.hasOption("o")) {
try {
- out = new BufferedOutputStream(new FileOutputStream(args.getOptionValue("o")));
+ out = new PrintStream(new FileOutputStream(args.getOptionValue("o")), true);
+ System.setOut(out);
} catch (FileNotFoundException e) {
log.error(e.getMessage(), e);
}
- } else {
- out = new BufferedOutputStream(System.out);
}
String[] includes = (System.getenv().containsKey("MQDSL_INCLUDE") ?
@@ -159,6 +160,9 @@ public static void main(String[] argv) {
binding.setVariable("mq", builder);
String fileBaseName = filename.replaceAll("\\.groovy$", "");
binding.setVariable("log", LoggerFactory.getLogger(fileBaseName.substring(fileBaseName.lastIndexOf("/") + 1)));
+ if (null != out) {
+ binding.setVariable("out", out);
+ }
// Include helper files
GroovyShell shell = new GroovyShell(binding);
@@ -182,15 +186,17 @@ public static void main(String[] argv) {
while (builder.isActive()) {
try {
- Thread t = Thread.currentThread();
- synchronized (t) {
- t.wait(500);
- }
+ Thread.sleep(500);
} catch (InterruptedException e) {
log.error(e.getMessage(), e);
}
}
+ if (null != out) {
+ out.close();
+ System.setOut(stdout);
+ }
+
} finally {
System.exit(0);
}

0 comments on commit c75264e

Please sign in to comment.