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
  • 6,706
  • 10
  • 30
  • 37
u123
  • 14,161
  • 51
  • 160
  • 272

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
  • 22,960
  • 2
  • 36
  • 51