开发者

Execute Unix cat command in Groovy?

Hallo

I would like to execute something like cat /path/to/file1 /path/to/file2 > /path/to/file3 from a Groovy program. I tried "cat /path/to/file1 /path/to/file2 > /path/to/file3".execute() but this didn't work.

After some searching I read about开发者_开发知识库 sh -c. So I tried "sh -c cat /path/to/file1 /path/to/file2 > /path/to/file3".execute(), but that didn't work either.

Do you have any suggestions?


I believe you need to use the List.execute() method to get this running in the Shell, ie:

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

Or, you could do it the groovy way

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


Perhaps you need provide the full path to the executable? "/bin/sh -c '/bin/cat file1 file2 >file3'".execute()

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜