Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I redirect output to stderr in groovy?

I'm looking for a way to redirect output in a groovy script to stderr:

catch(Exception e) {
    println "Want this to go to stderr"
}
like image 947
timdisney Avatar asked Dec 19 '08 19:12

timdisney


3 Answers

Just off the top of my head couldn't you do a bit of self-wiring:

def printErr = System.err.&println printErr("AHHH") 

but that is a bit manual

like image 126
codeLes Avatar answered Oct 06 '22 01:10

codeLes


Groovy has access to the JRE:

System.err.println "goes to stderr" 

Although there may be a more Groovy-fied way...

like image 29
Dan Vinton Avatar answered Oct 06 '22 01:10

Dan Vinton


Another quite compact alternative is this:

System.err << "Want this to go to stderr"

Or you could add this at the top of your script

def err = System.err
...
err << "Want this to go to stderr"

which is what I'm now doing in my groovy shell scripts

like image 35
James Frost Avatar answered Oct 06 '22 00:10

James Frost