在Groovy中执行Unix cat命令? [英] Execute Unix cat command in Groovy?

查看:118
本文介绍了在Groovy中执行Unix cat命令?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hallo



我想从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(),但这也不起作用。 b
$ b

你有什么建议吗?

解决方案

我相信你需要使用 List.execute() code> 方法来让它在Shell中运行,即:

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

或者,您可以按照常规方式进行操作

 新档案('file3').with {f  - > 
['file1','file2'] .each {f<<新文件(it).asWritable()}
}


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() }
}

这篇关于在Groovy中执行Unix cat命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆