firing curl script using sample code - fireCommandExec

Hi All,

I am trying to send an image location url using curl script to a restful webservice. The script is working fine when i run it directly on my server unix box. However while trying to fire the script using the sample code - fireCommandExec, i am getting
the below error.

500 internal server error.
We’re sorry but a serious error has occurred in the system.

curl script -
curl -k -i -u username:password -H “Content-Type=multipart/form-data” --data “imageURI=imageLocationURL” -X POST endPointURL

java code used to fire the command -
Process child = Runtime.getRuntime().exec(command);

Kindly help me to resolve the issue and let me know if i am doing anything wrong.


Please paste your full java code.


PFB the java code. However I do not feel the issue is with java code. The same code was tried in eclipse, and the script was run without any issue.

Process child = Runtime.getRuntime().exec(command);

    // read stdout; required to keep this process from becoming a zombie
    InputStream stdout = child.getInputStream();
    BufferedReader reader = new BufferedReader(new InputStreamReader(stdout));

    int siz = 1024;
    char[] buff = new char[siz];

    int r = 0;
    StringBuffer sbf = new StringBuffer();
    while ( ( r =, 0, siz) ) > 0 )
        sbf.append(buff, 0, r);
    stdoutText = sbf.toString();

    // read stderr; required to keep this process from becoming a zombie
    InputStream stderr = child.getErrorStream();
    reader = new BufferedReader(new InputStreamReader(stderr));

    StringBuffer sbf2 = new StringBuffer();
    while ( ( r =, 0, siz) ) > 0 )
        sbf2.append(buff, 0, r);
    stderrText = sbf2.toString();

    child.waitFor(); // IllegalThreadStateException, if w/o wait & child not terminated
    status = child.exitValue();

Is the target RESTful web service implemented by Jive REST API? It looks like a server side error, your java code is ok, you’d better confirm this with web service provider.


Yes, the target is a jive REST API. However what confuses me is that, when i try to run the same curl script from my server unix box i get success response.

There is something different between Runtime.exec invoke and directly shell invoke about parse the args.
May be you can try Runtime.getRuntime().exec(new String{“curl”, “-k”, “-i”, “-u”, …}) instead.


I tried that and it did not work. Also i was able to run another curl script to upload an image to the jive rest API using the same code.


Is there anything else i can try? :frowning: Not sure what is the issue. I checked with the webservice provider, and they have no error logs at their end to help the situation.

I think there is one more thing you can try. As you said:

May be you can try to write this script into a .sh file, and execute it by Runtime.exec.

Thanks a lot! That worked :slight_smile: