tim*_*tes 16
不确定我理解你的问题.
你的意思是进行系统调用并管道结果吗?
如果是这样,您可以执行以下操作:
println 'cat /Users/tim_yates/.bash_profile'.execute().text
Run Code Online (Sandbox Code Playgroud)
打印文件的内容
您也可以管道进程输出:
def proc = 'cat /Users/tim_yates/.bash_profile'.execute() | 'grep git'.execute()
println proc.text
Run Code Online (Sandbox Code Playgroud)
如果要获取File使用标准Groovy API调用的文本,可以执行以下操作:
println new File( '/Users/tim_yates/.bash_profile' ).text
Run Code Online (Sandbox Code Playgroud)
这会得到一个文件中的行列表,找到包含该单词的所有内容,git然后依次打印出每个行:
new File( '/Users/tim_yates/.bash_profile' ).text.tokenize( '\n' ).findAll {
it.contains 'git'
}.each {
println it
}
Run Code Online (Sandbox Code Playgroud)