/** * @author :ZackZhou * @date :Created in 2020/10/22 5:25 PM * @description : * @modified By: * @version: */ //approach 1 def sout = new StringBuilder() def serr = new StringBuilder() def command = ['bash','-c','ls;sleep 2; ls -lhst'] def proc = command.execute() proc.consumeProcessOutput(sout,serr) proc.waitForOrKill(5000) println(sout.toString()) //approach 2 def commands = ['bash','-c','ls;sleep 2; ls -lhst'] println commands.execute().text //execute scripts def file = new File("./BashScript.sh") def command_file = file.text println command_file.execute().text