cancel
Showing results for 
Search instead for 
Did you mean: 

Get returned value on Curl

sakshik
Star Contributor
Star Contributor

I have a main function in my webscript:

mywebscript.js

function main()

{

....

....

return arr;

}

main();

How do I get arr when I call this script using curl command.

curl "http://.../alfresco/service/mywebscript"

1 ACCEPTED ANSWER

cesarista
World-Class Innovator
World-Class Innovator

Hi:

Your freemaker template may render in json format, and then you can parse your curl result via jq or jshon commands instead of greping this way.

Regards.

--C. 

View answer in original post

4 REPLIES 4

afaust
Legendary Innovator
Legendary Innovator

You must write a response template using FreeMarker template to render the HTTP response. You will not automatically get "arr" as a response. Also, for the template to be able to render elements of "arr" you must put it into the "model" variable, e.g. "model.arr = arr;"

sakshik
Star Contributor
Star Contributor

Yeah I can write "model.arr = arr" in my script and fetch its value in FreeMarker template using ${arr}. but arr is an associative array and I need to loop through that and feed the values into an sql table which is where I am calling the curl command in a ruby based script.

I can fetch the value of a <p></p> tag of FreeMarker template file using :

curl "http://.../alfresco/service/mywebscript" | grep  \'(?<=<p>).*?(?=</p>)\' but I cannot grep on a table and get the value of multiple <td></td>s.

And that is why I need arr to fetch where I am calling curl.

cesarista
World-Class Innovator
World-Class Innovator

Hi:

Your freemaker template may render in json format, and then you can parse your curl result via jq or jshon commands instead of greping this way.

Regards.

--C. 

Rendering in json ftl worked .

Thank you.