groovy 使用包含空格的参数执行 [英] groovy execute with parameters containing spaces

查看:20
本文介绍了groovy 使用包含空格的参数执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何向 groovy 中字符串的 execute 方法提供包含空格的参数?只是像在 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.

推荐答案

诀窍是使用列表:

println(['ls', '/tmp/folder with spaces'].execute().text)

这篇关于groovy 使用包含空格的参数执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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