Cedric Greevey <cgree...@gmail.com> writes: Hi Cedric,
>> Just in case the java lib in fact uses System.out/err directly, one >> can redirect standard out and error to something else. >> >> (with-open [w (clojure.java.io/writer "/dev/null")] >> (binding [*out* w, *err* w] >> (.noisyJavaCall1 1 2 3) >> (.noisyJavaCall2 3 2 1))) >> >> Of course, /dev/null is somewhat platform specific. > > Will that work? I was under the impession that binding *out* and *err* > had no effect on System/out or System/err. No, it won't work. I tested it briefly in a slime repl and forgot the fact that java sysouts aren't printed in there anyway. So using your setOut/Err() advice, here's a java quitening macro that actually works: --8<---------------cut here---------------start------------->8--- (defmacro without-java-output [& body] `(with-open [w# (java.io.PrintStream. "/dev/null")] (let [oo# System/out, oe# System/err] (System/setOut w#) (System/setErr w#) (try ~@body (finally (System/setOut oo#) (System/setErr oe#)))))) (without-java-output (.println System/out "Hello out") (.println System/err "Hello err")) --8<---------------cut here---------------end--------------->8--- Bye, Tassilo -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en