To capture the output of process in Groovy I use the following:
"command".execute().text
I want to do the same in Java, but all responses I found contain a lot of boilerplate code involving loops, BufferedReader
, Scanner
, etc.:
- Get Command Prompt Output to String In Java
- How to run Windows commands in JAVA and return the result text as a string
- java runtime.getruntime() getting output from executing a command line program
Can I do the same thing within 1-2 lines of code? Maybe Guava or Apache have something to make life simpler?