我想写一个包装另一个命令的Groovy脚本,并且遇到stdout/stderr命令有问题。我的脚本如下:为什么输出显示顺序错误?
#!/usr/bin/env groovy
synchronized def output = ""
def process = "qrsh ${args.join(' ')}".execute()
def outTh = Thread.start {
process.in.eachLine {
output += it
System.out.println "out: $it"
}
}
def errTh = Thread.start {
process.err.eachLine {
output += it
System.err.println "err: $it"
}
}
outTh.join()
errTh.join()
process.waitFor()
System.exit(process.exitValue())
我的问题是输出没有以正确的顺序出现在终端上。以下是包装器的输出。
[<cwd>] wrap.groovy -cwd -V -now n -b y -verbose ant target
waiting for interactive job to be scheduled ...
Your interactive job 2831303 has been successfully scheduled.
Establishing builtin session to host <host> ...
Buildfile: build.xml
BUILD FAILED
Target "target" does not exist in the project "null".
Total time: 0 seconds
Your job 2831303 ("wrap.groovy") has been submitted
下面是unwrapped命令输出。
[<cwd>] qrsh -cwd -V -now n -b y -verbose ant target
Your job 2831304 ("ant") has been submitted
waiting for interactive job to be scheduled ...
Your interactive job 2831303 has been successfully scheduled.
Establishing builtin session to host host ...
Buildfile: build.xml
BUILD FAILED
Target "target" does not exist in the project "null".
Total time: 0 seconds
为什么“您的工作已被提交”消息显示为一个演员的第一行,另一个演员的最后一行?我猜它与Java库有关,而不是Groovy。
我理解与流之间的相对顺序的问题,但是应该在每个流内的顺序是否正确?我没有显示由源注释的行,但stdout顺序不正确。我也写了一个Perl包装器,它也有同样的问题。是否有可能将正在移动的线路直接写入终端?看起来,它仍然使得它stdout虽然.. – dromodel 2011-02-10 16:27:07