It seems that the shell / data console interprets / changes characters. For example, the following line:
-H "Content-Type: application/json"
... seems to be interpreted as three different arguments:
-H Content-Type: and application and /json using the shell / console.
Try breaking the command line into an array of components using the format:
exec(String[] cmdarray)
Thus, it will be clear that the shell / console with which the arguments are grouped,
Here is a groovy test that proves the point:
def Object executeCommand(command) { def proc = Runtime.getRuntime().exec(command); def sout = new StringBuffer() def serr = new StringBuffer() proc.consumeProcessOutput(sout, serr) proc.waitFor() return [ 'sout':sout.toString(), 'serr':serr.toString() ] } response = executeCommand('''curl --silent --show-error -H "Accept: application/json" --request GET "https://education.cloudant.com/"''') assert response['sout'] == '' assert response['serr'].startsWith( 'curl: (6) Could not resolve host: application' ) response = executeCommand(['curl', '--silent', '--show-error', '-H', 'Accept: application/json', '--request', 'GET', 'https://education.cloudant.com/'] as String[] ) assert response['sout'].startsWith('{"couchdb":"Welcome","version":"1.0.2","cloudant_build":"2367"}') assert response['serr'] == ''
source share