当 groovy 调用 bash 时,调试模式"-x"在标准输出中不可见



我们正在使用groovy执行一个bash脚本,其中包含调试模式set -x。我们像这样运行它:

    def proc = "bash hello.sh".execute()  
    proc.in.eachLine { line -> println line }
    proc.waitForOrKill(100*1000)             

当我们在命令提示符下使用bash hello.sh直接运行它时,我们看到回显行和+行:

Tue Jun 11 10:52:42 IDT 2013:: Running 
+ mkdir -p folder
+ tar -xzf file
...

但是当我们从groovy中运行它时,只有回显行是可见的!

Tue Jun 11 10:52:42 IDT 2013:: Running

怎么回事?这是groovy/Java bug吗?

尝试添加

proc.consumeProcessOutput(System.out, System.err)

在你等待它完成之前(代替你的proc.in.eachLine行)

最新更新