unix - 在 Groovy 中执行 Unix cat 命令?

标签 unix groovy

你好

我想从 Groovy 程序中执行类似 cat/path/to/file1/path/to/file2 >/path/to/file3 的操作。 我尝试了“cat/path/to/file1/path/to/file2 >/path/to/file3”.execute() 但这没有用。

经过一些搜索,我读到了有关 sh -c 的信息。所以我试过了 “sh -c cat/path/to/file1/path/to/file2 >/path/to/file3”.execute(),但这也不起作用。

你有什么建议吗?

最佳答案

我相信您需要使用 List.execute()在 Shell 中运行它的方法,即:

[ 'sh', '-c', 'cat file1 file2 > file3' ].execute()

或者,你可以用常规方式来做

new File( 'file3' ).with { f ->
  [ 'file1', 'file2' ].each { f << new File( it ).asWritable() }
}

关于unix - 在 Groovy 中执行 Unix cat 命令?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6008691/

相关文章:

linux - 如何使用 Unix 脚本强制启动 Control M 作业

linux - 你能在linux系统上隐藏文件夹的 'date modified'时间吗?

unix - 将命令输出 append 到不带换行符的文件

spring - 在grails应用程序中多次触发Datasource.groovy(第二次调用时抛出异常)

shell - 将 groovy 脚本作为文件发送到 Gremlin Server REST API

linux - 找出谁/什么在调用脚本(cron)

perl - 如何在Unix上的多个文件中的特定行插入一行?

reflection - 如何使用 Groovy 获取没有继承方法的类的所有方法名称?

spring - 无法在spring boot中启动嵌入式Tomcat

grails - 在 Grails 中使用特征进行水平域类重用,是个好主意吗?