简体   繁体   English

windows命令行管道一个字符串到groovy

[英]windows command line pipe a string to groovy

I'm on Windows 7 64-bit and want to do something like below on the command line using Groovy: 我在Windows 7 64位上,并希望使用Groovy在命令行上执行类似下面的操作:

echo "println('Hello, World...')" | echo“println('Hello,World ...')”| groovy -e groovy -e

But I can't seem to get the echo o/p to pass as i/p to the groovy command, and keep getting the below error: 但我似乎无法将echo o / p作为i / p传递给groovy命令,并继续得到以下错误:

error: illegal use of -e (requires a value) 错误:非法使用-e(需要一个值)

Can someone please help? 有人可以帮忙吗?

Groovy doesn't have an option for reading the script from standard input. Groovy没有从标准输入读取脚本的选项。 The -e option is used to specify the script on the command line like this: -e选项用于在命令行上指定脚本,如下所示:

groovy -e "println('Hello World')"

If you really need to run a script piped into standard input, try this: 如果您确实需要运行管道传输到标准输入的脚本,请尝试以下操作:

echo println('Hello World') | groovy -e 'new GroovyShell().evaluate(System.in)'

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

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