java - using curl with Runtime.getRuntime().exec java - using curl with Runtime.getRuntime().exec curl curl

java - using curl with Runtime.getRuntime().exec


I don't have a direct answer, but a bit on the way is that the apostrophe gets encoded differently. Although an old question, I'll answer to for future reference, and maybe someone can explain the complete answer later.

When I test our API in a similar way I notice the following:

curl -i http://localhost:8080/auth/login -d 'identifier=test@example.com&password=test'

This command, when sent from shell, ends up in the server as:

identifier=test@example.com,\npassword=test,\n

but when sent from Runtime.getRuntime().exec(command), it ends up as:

'identifier=test@example.com,\npassword=test',\n

If I change the curl command and remove the apostrophes, it works (due to the essence of this command)

 curl -i http://localhost:8080/auth/login -d identifier=test@example.com&password=test

Thus a fait guess is that if the code in the question is changed to this, it may actually work if the file name contains no space...:

String command = "curl -X POST " + header + "--data-binary @"        + fileName + " https://api.parse.com/1/files/" + fileName;

One option would be to use the execute command with an array of inputs as described here: Runtime Exec seems to be ignoring apostrophes In combination of parsing the curl command (unless hard coded) as described here: Split string on spaces in Java, except if between quotes (i.e. treat \"hello world\" as one token)


I guess you get an Errorcode from Curl not the exception, check the Curl API again, u guess you will find any missing parameter like "User" or other stuff.

You can try to check some of the hints mentioned in this answer.