概述class StreamConsumer extends Thread{ def inStream def buf public StreamConsumer(def input){ inStream = input buf = new StringBuffer() } public void run(){ class StreamConsumer extends Thread{ def inStream def buf public StreamConsumer(def input){ inStream = input buf = new StringBuffer() } public voID run(){ def reader = new BufferedReader(new inputStreamReader(inStream)) reader.eachline{ buf.append(it).append('/n')} } } class Exec{ static def doCommand(def cmd){ Process proc = Runtime.getRuntime().exec(cmd) def error = new StreamConsumer(proc.getErrorStream()) def input = new StreamConsumer(proc.getinputStream()) input.start() error.start() proc.waitFor() input.join() error.join() return [ "stdout":input.buf?.toString().trim(), "stderr":error.buf?.toString().trim(), ] } } def cmd = 'dir ' def result = Exec.doCommand(cmd); println result 具体的解释请参考 When Runtime.exec() won't http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.HTML?page=3 总结
以上是内存溢出为你收集整理的如何正确的使用groovy调用外部程序全部内容,希望文章能够帮你解决如何正确的使用groovy调用外部程序所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
评论列表(0条)