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()
精彩评论