[英]Assign Linux Command to Variable in Groovy
I'm attempting to run a linux command, curl, through groovy, and would like the output to be assign to a variable. 我正在尝试通过groovy运行linux命令curl,并希望将输出分配给变量。 I'd like to do this, so I can extract specific data from the curl output, and use in in my groovy script. 我想这样做,因此我可以从curl输出中提取特定数据,并在groovy脚本中使用。
Any ideas, how I can do this. 任何想法,我该怎么做。
I've tried, 我试过了,
def after = "curl \"https://test.com\"".execute()
def after = "curl \"https://test.com\"".execute().text
but the variable is always empty. 但变量始终为空。 Any help would be appreciated. 任何帮助,将不胜感激。
linux command with spaces needs to be separated. 带空格的linux命令需要分开。
["/bin/sh", "-o", "your_command"].execute()
In your case it would be something like below: 您的情况如下所示:
["curl", "https://test.com"].execute()
OR 要么
def after = ["curl", "https://test.com"].execute().text
Try and see if it works. 尝试看看是否可行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.