groovy使用包含空格的参数执行 [英] groovy execute with parameters containing spaces
本文介绍了groovy使用包含空格的参数执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在groovy中为包含空格的字符串的执行方法提供参数?在shell中添加空格不会有帮助:
How do I provide arguments containing spaces to the execute method of strings in groovy? Just adding spaces like one would in a shell does not help:
println 'ls "/tmp/folder with spaces"'.execute().text
这会给ls调用带来三个错误的参数。
This would give three broken arguments to the ls call.
推荐答案
诀窍是使用一个列表:
The trick was to use a list:
println(['ls', '/tmp/folder with spaces'].execute().text)
这篇关于groovy使用包含空格的参数执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文