1

I'm trying to use CURL inside a windows batch file. I need to capture the response inside a variable but am struggling. I have tried several syntaxes and if I attempt to use curl_setopt I get an error about the Environment variable not being defined. Going back to basics I started with ...

set response = curl http://www.google.co.uk

Any help would be greatly appreciated.

1 Answer 1

2
@echo off
setlocal disableDelayedExpansion
REM Creating a Newline variable (the two blank lines are required!)
set NLM=^


set NL=^^^%NLM%%NLM%^%NLM%%NLM%

setlocal enableDelayedExpansion
set "response="
for /f "delims=" %%r in ('curl http://www.google.co.uk 2^>^&1') do (
  set response=!response!%NL%%%r 
)
echo %response%
endlocal
endlocal
Sign up to request clarification or add additional context in comments.

2 Comments

Why the quotes in set "response=" when set response= works just as well?
@ErikE: that ensures String

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.