Skip to content

Instantly share code, notes, and snippets.

View devilelephant's full-sized avatar

George Coller devilelephant

  • Minneapolis, MN
View GitHub Profile
@devilelephant
devilelephant / gist:6554811
Created September 13, 2013 19:12
An easy way to do Unix piping when executing Unix commands from Java or Groovy In unix you can issue a command like: sh -c 'ls -l | sort" which is calling the 'sh' shell with a command and returning the result. I wrote the example in groovy but the trick works with Runtime.exec(String[] cmd) as well.
def cmd = ['sh', '-c', 'ls -l | sort']
def p = cmd.execute()
println p.text
// Java would be something like
// String[] cmd = { "sh", "-c", "ls -l | sort" };
// Process p = Runtime.getRuntime().exec(cmd);
// ...
@devilelephant
devilelephant / gist:6554529
Created September 13, 2013 18:48
Groovy XML Markup Builder Tricks: CDATA, declaration, comments
def out = new StringWriter()
def xml = new groovy.xml.MarkupBuilder(out)
// MarkupBuilder gives us an instance of MarkupBuilderHelper named 'mkp'
// MarkupBuilderHelper has several helpful methods
xml.mkp.xmlDeclaration(version: "1.0", encoding: "utf-8")
xml.example {
a {
b {
mkp.comment('a comment')