Well, when I pack my project into a stand alone jar and run java -jar
myproject-standalone.jar inside a terminal, the Android controller's debug
information gets printed out which clusters the terminal output, making
other vital information hard to identify. Thus I would want to find a way
to suppress its output.
BTW, I came up with an UGLY solution:
(let [err System/err]
(System/setErr (java.io.PrintStream. (java.io.FileOutputStream.
"/dev/null")))
(try
(throw (Exception. "Hello"))
(catch Exception e (.printStackTrace e)))
(System/setErr err))
This time, the stack trace gets suppressed. But it looks really UGLY and by
no means, in efficient as it opens /dev/null everytime.
What is the difference between *err* and System/err?!
2013/3/5 Jim - FooBar(); <[email protected]>
> still doesn't work though! strange...
> why would you want to do this anyway?
>
> Jim
>
>
>
> On 05/03/13 14:35, Jim - FooBar(); wrote:
>
> but then it's pretty trivial to adapt it:
>
> (defmacro with-out-err-str
> "Evaluates exprs in a context in which *out* and *err* ire bound to a fresh
> StringWriter. Returns the string created by any nested printing
> calls."
> {:added "1.0"}
> [& body]
> `(let [s# (new java.io.StringWriter)]
> (binding [*out* s# *err* s#]
> ~@body
> (str s#))))
>
> Jim
>
>
>
>
> On 05/03/13 14:33, Jim - FooBar(); wrote:
>
> aaa sorry...I guess I should have tested first...
>
> Jim
>
>
> On 05/03/13 14:24, bruce li wrote:
>
> Thanks, Jim. But with-out-str only works for output to *out*(stdout), but
> not *err*(stderr). A quick test is:
> (with-out-str
> (try
> (throw (Exception. "Hello"))
> (catch Exception e
> (.printStackTrace e))))
> which it returns: "" but the stack trace still gets printed out:
> java.lang.Exception: Hello
> at user$eval2774$fn__2775.invoke(NO_SOURCE_FILE:1)
> at user$eval2774.invoke(NO_SOURCE_FILE:1)
> at clojure.lang.Compiler.eval(Compiler.java:6511)
> at clojure.lang.Compiler.eval(Compiler.java:6477)
> at clojure.core$eval.invoke(core.clj:2797)
> at clojure.main$repl$read_eval_print__6405.invoke(main.clj:245)
> at clojure.main$repl$fn__6410.invoke(main.clj:266)
> at clojure.main$repl.doInvoke(main.clj:266)
> at clojure.lang.RestFn.invoke(RestFn.java:1096)
> at
> clojure.tools.nrepl.middleware.interruptible_eval$evaluate$fn__1402.invoke(interruptible_eval.clj:57)
> at clojure.lang.AFn.applyToHelper(AFn.java:159)
> at clojure.lang.AFn.applyTo(AFn.java:151)
> at clojure.core$apply.invoke(core.clj:601)
> at clojure.core$with_bindings_STAR_.doInvoke(core.clj:1771)
> at clojure.lang.RestFn.invoke(RestFn.java:425)
> at
> clojure.tools.nrepl.middleware.interruptible_eval$evaluate.invoke(interruptible_eval.clj:42)
> at
> clojure.tools.nrepl.middleware.interruptible_eval$interruptible_eval$fn__1443$fn__1445.invoke(interruptible_eval.clj:170)
> at clojure.core$comp$fn__4034.invoke(core.clj:2278)
> at
> clojure.tools.nrepl.middleware.interruptible_eval$run_next$fn__1436.invoke(interruptible_eval.clj:137)
> at clojure.lang.AFn.run(AFn.java:24)
> at
> java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
> at
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
> at java.lang.Thread.run(Thread.java:722
>
> 2013/3/5 Jim - FooBar(); <[email protected]>
>
>> I don't know if you can suppress it, but you can certainly ignore it with
>> 'without-str' which will give you what was supposed to be printed out, as a
>> string...then it's up to you what to do with it... :)
>>
>> HTH,
>> Jim
>>
>>
>> On 05/03/13 08:56, bruce li wrote:
>>
>>> Hi, guys,
>>>
>>> I'm currently playing clojure with android monkey runner. So far it
>>> works fine but just one unpleasant thing -- the android monkey runner
>>> default prints a lot of junk information to stderr such as:
>>>
>>> March 05, 2013 4:46:47 pm com.android.chimpchat.ChimpManager
>>> sendMonkeyEventAndGetResponse
>>>
>>> These printing operations are evaluated inside its library when I call a
>>> method such as IChimpDevice.touch.
>>>
>>> I'm writing some wrappers around the api:
>>>
>>> (defn send-touch [^IChimpDevice device x y]
>>> (.touch device x y TouchPressType/DOWN_AND_UP))
>>>
>>> Is it possible to suppress the its output to stderr and make it
>>> something like(in pseudo code):
>>> (with-stderr-discard
>>> (.touch device x y TouchPressType/DOWN_AND_UP))
>>>
>>> I cannot discard the whole program's stderr output with commands like
>>> java -jar xxxxxx.jar 2>/dev/null
>>>
>>> since I need vital stack trace information from other places for debug
>>> purpose.
>>>
>>> Any help would be appreciated.
>>>
>>>
>>> --
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Clojure" group.
>>> To post to this group, send email to [email protected]
>>> Note that posts from new members are moderated - please be patient with
>>> your first post.
>>> To unsubscribe from this group, send email to
>>> [email protected]
>>> For more options, visit this group at
>>> http://groups.google.com/group/clojure?hl=en
>>> ---
>>> You received this message because you are subscribed to the Google
>>> Groups "Clojure" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to [email protected].
>>> For more options, visit https://groups.google.com/groups/opt_out.
>>>
>>>
>>>
>> --
>> --
>> You received this message because you are subscribed to the Google
>> Groups "Clojure" group.
>> To post to this group, send email to [email protected]
>> Note that posts from new members are moderated - please be patient with
>> your first post.
>> To unsubscribe from this group, send email to
>> [email protected]
>> For more options, visit this group at
>> http://groups.google.com/group/clojure?hl=en
>> --- You received this message because you are subscribed to the Google
>> Groups "Clojure" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [email protected].
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>>
>>
> --
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to [email protected]
> Note that posts from new members are moderated - please be patient with
> your first post.
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
> ---
> You received this message because you are subscribed to the Google Groups
> "Clojure" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>
>
>
>
> --
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to [email protected]
> Note that posts from new members are moderated - please be patient with
> your first post.
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
> ---
> You received this message because you are subscribed to the Google Groups
> "Clojure" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>
--
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.