unix – 在groovy中有grep,pipe,cat的API吗?
发布时间:2020-12-15 22:39:20 所属栏目:安全 来源:网络整理
导读:在groovy中有grep,pipe,cat的API吗? 解决方法 不确定我理解你的问题. 你的意思是进行系统调用并管道结果吗? 如果是这样,您可以执行以下操作: println 'cat /Users/tim_yates/.bash_profile'.execute().text 打印文件的内容 您也可以管道进程输出: def pr
在groovy中有grep,pipe,cat的API吗?
解决方法
不确定我理解你的问题.
你的意思是进行系统调用并管道结果吗? 如果是这样,您可以执行以下操作: println 'cat /Users/tim_yates/.bash_profile'.execute().text 打印文件的内容 您也可以管道进程输出: def proc = 'cat /Users/tim_yates/.bash_profile'.execute() | 'grep git'.execute() println proc.text 如果要使用标准Groovy API调用获取文件的文本,可以执行以下操作: println new File( '/Users/tim_yates/.bash_profile' ).text 这将获取文件中的行列表,找到包含单词git的所有行,然后依次打印每个行: new File( '/Users/tim_yates/.bash_profile' ).text.tokenize( 'n' ).findAll { it.contains 'git' }.each { println it } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |