0

Based on:

Groovy executing shell commands

I have this groovy script:

def proc = "some bash command".execute()

//proc.out.close() // hm does not seem to be needed...
proc.waitFor()

if (proc.exitValue()) {
  def errorMsg = proc.getErrorStream().text
  println "[ERROR] $errorMsg"
} else {
  println proc.text
}

That I use the execute various linux bash commands. Currently it works fine even without the proc.out.close() statement.

What is the purpose of proc.out.close() and why is it (not?) needed

Nic3500
  • 8,144
  • 10
  • 29
  • 40
u123
  • 15,603
  • 58
  • 186
  • 303

1 Answers1

1

proc.text is actually proc.getText()

form groovy api doc: Read the text of the output stream of the Process. Closes all the streams associated with the process after retrieving the text.

http://docs.groovy-lang.org/docs/latest/html/groovy-jdk/java/lang/Process.html#getText()

So, when using proc.text you don't need to call proc.out.close()

daggett
  • 26,404
  • 3
  • 40
  • 56