Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Groovy process.text的等效错误?_Groovy - Fatal编程技术网

Groovy process.text的等效错误?

Groovy process.text的等效错误?,groovy,Groovy,通过使用.text: def process = "ls -l".execute() println "Found text ${process.text}" 是否有一个简洁的等价物来获取错误流?您可以使用waitForProcessOutput,它包含两个可追加项() 根据tim_yates的回答,我在Jenkins身上试过,发现了多重作业的问题: 因此,这是可行的,也是简明的: def process = "ls -l".execute() def output = new StringW

通过使用.text:

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

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

您可以使用
waitForProcessOutput
,它包含两个可追加项()


根据tim_yates的回答,我在Jenkins身上试过,发现了多重作业的问题:

因此,这是可行的,也是简明的:

def process = "ls -l".execute()
def output = new StringWriter(), error = new StringWriter()
process.waitForProcessOutput(output, error)
println "exit value=${process.exitValue()}"
println "OUT: $output"
println "ERR: $error"

我接受你的回答,因为这是迄今为止最简洁的。我想知道为什么没有
进程.error
。主要是因为使用.text成员很危险。如果输出或错误流的文本输出超过buffersize,则进程将停止,直到读取部分流。当您不知道输出将持续多长时间(通常是错误情况)时,使用单独的线程捕获流是一个好主意。@BillJames comment的+1。另一方面,这就是(创建两个线程来侦听输出)这里的splat操作符是什么?我以前没见过这个。获取字符串值并将每个值分配给声明的相应变量是一个扩展运算符吗?是的
def process = "ls -l".execute()
def output = new StringWriter(), error = new StringWriter()
process.waitForProcessOutput(output, error)
println "exit value=${process.exitValue()}"
println "OUT: $output"
println "ERR: $error"