如何将所有输出从groovy脚本重定向到另一个流,而不更改脚本?

时间:2011-12-25 17:55:20

标签: groovy

This questionan accepted answer仅将out“命令”重定向到输出流。我想将脚本中的所有输出重定向到流,而不仅仅是使用out << "hello world"命令创建的输出的子集。

This answer更改脚本以通过out“command”写入其所有输出。是否有一个不需要更改脚本的可靠解决方案?

1 个答案:

答案 0 :(得分:1)

您可以将System.out绑定到另一个流,例如(如果您从普通Java中调用它):

PrintStream ps = new PrintStream(new FileOutputStream("console.out"));
System.setOut(ps);
//call your script there

或更多groovier:

System.out = new File('console.out').newPrintWriter()
//call your script there
相关问题