This curl command works in the terminal but fails in groovy. I added the err and out out from another question to try and understand why it fails.
def initialSize = 4096
def out = new ByteArrayOutputStream(initialSize)
def err = new ByteArrayOutputStream(initialSize)
def process = "sh -c curl'https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts'".execute()
process.consumeProcessOutput(out, err)
process.waitFor()
println process.text
println err.toString()
println out.toString()
The output is "curl: try 'curl --help' or 'curl --manual' for more information"
Don't use string for execute, as Groovy will split on whitespace. You have to pass the "shell command" as a single argument to sh -c. So right now you a) lack a space between curl and the url and b) this will end up as two arguments (and you can not quote for that).
Use a string list instead:
['sh', '-c', "curl 'http://...'"].execute()
Also on a sidenote: if you just want the content of a url and don't need fancy things (timeouts, auth, ...), you can just as well do:
"https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts".toURL().text
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With