一个等同于process.text的错误? [英] An error equivalent for process.text?

查看:77
本文介绍了一个等同于process.text的错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您可以使用.text获取整个输出流

  def process =ls -l.execute()
printlnFound text $ {process.text}

是否有简洁的等价物来获取错误流?

解决方案

您可以使用 waitForProcessOutput ,它需要两个Appendables( docs here

  def process =ls -l.execute()
def(output,error)= new StringWriter()。with {o - > //对于输出
new StringWriter()。with {e - > //对于错误流
process.waitForProcessOutput(o,e)
[o,e] *。toString()//返回它们两个
}
}
//将其打印出来...
printlnOUT:$ output
printlnERR:$ error


You can get the entire output stream by using .text:

def process = "ls -l".execute()
println "Found text ${process.text}"

Is there a concise equivalent to get the error stream?

解决方案

You can use waitForProcessOutput which takes two Appendables (docs here)

def process = "ls -l".execute()
def (output, error) = new StringWriter().with { o -> // For the output
  new StringWriter().with { e ->                     // For the error stream
    process.waitForProcessOutput( o, e )
    [ o, e ]*.toString()                             // Return them both
  }
}
// And print them out...
println "OUT: $output"
println "ERR: $error"

这篇关于一个等同于process.text的错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆