你好
我想从 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/