Friday, 15 February 2013

Save CURL is output into a variable in batch file -



Save CURL is output into a variable in batch file -

hi first post if haven't formatted correctly or not on topic please allow me know.

i need utilize curl access database , extract datapoints each device stored in cloud. question far how save access token line:

`curl -x post -d "<user><email>myemail@anexample.com</email><password>passwordexample</password><application><app_id>anidexample_id</app_id><app_secret>asecretexample_secret</app_secret></application></user>" -h "content-type:application/xml" https://user.aylanetworks.com/users/sign_in.xml`

into variable.

so far i've used :

@echo off set /p userinput= come in access token: @echo on curl -h "authorization: auth_token %userinput%" https://ads-dev.aylanetworks.com/apiv1/dsns/ac000w000007000/properties.xml>testfile.xml

this passes token needs entered manually every time. i've tried utilize set without needing user input , haven't been able working. there i'm missing setting variables?

any help appreciated,

dm

assuming curl's xml response :

<?xml version="1.0" encoding="utf-8"?> <authorization> <access-token>0317080d361a430bb81e3997114267bf</access-token> <refresh-token>c696753bddb4459c9a8ceb54fa04d53b</refresh-token> <expires-in type="integer">86400</expires-in> <role>oem::staff</role> <role-tags type="array"/> </authorization>

you can seek :

@echo off set url="<user><email>myemail@anexample.com</email><password>passwordexample</password><application><app_id>anidexample_id</app_id><app_secret>asecretexample_secret</app_secret></application></user>" /f "skip=2 tokens=3 delims=^<^>" %%a in ('curl -x post -d %url% -h "content-type:application/xml" https://user.aylanetworks.com/users/sign_in.xml') ( set "$token=%%a" goto:next) :next echo token : %$token% pause curl -h "authorization: auth_token %$token%" https://ads-dev.aylanetworks.com/apiv1/dsns/ac000w000007000/properties.xml>testfile.xml

i putted pause before sending sec request can check if there right value in %$token%

batch-file curl

No comments:

Post a Comment