简体   繁体   English

从 Java/Groovy 进程调用 ZSH 命令

[英]Invoking ZSH commands from Java/Groovy Process

Running the following Groovy code is giving me error : unmatched '运行以下 Groovy 代码给我错误: unmatched '

Process process = "zsh -c 'ls -l'".execute()

However, the following works fine Process process = "zsh -c ls".execute() .但是,以下工作正常Process process = "zsh -c ls".execute()

How to invoke a zsh command which takes multiple flags?如何调用带有多个标志的 zsh 命令?

Never ever use String.execute() - it will split on whitespace and is only sane for very simple commands.永远不要使用String.execute() - 它会在空格上拆分,并且仅适用于非常简单的命令。 The attempt in quoting is in vain in any case, because no shell is used here to parse the string.无论如何,引用的尝试都是徒劳的,因为这里没有使用 shell 来解析字符串。

Always use List.execute() instead.始终使用List.execute()代替。 Eg例如

["zsh", "-c", "ls -1"].execute()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM