Using for command starts/ends with double quote.
Posted: 01 May 2020 16:39
I'm making a code to get some value from website with curl and sed.
The website will include code that starts with name and ends with value with double quote.
In this code, I need [numbers].
Here is the code that I made to get [numbers].
The summarized code is:
curl will not be in %~dp0, so it must be enclosed in double quotes.
options for sed below should also be enclosed in double quote.
But For /f that starts/ends with double quote will not work as expected.
This code will not work if "curl path" contains special characters like "&"
This code will not work too.
Using CMD /C or moving to curl path is a not bad way, but I don't want to modify this code as much as possible.
Is there a simple way to use For /f that starts and ends with double quotes?
The website will include code that starts with name and ends with value with double quote.
Code: Select all
<div style="display:none;">
something="somethig"
categoryNo="[numbers]"
</div>
Here is the code that I made to get [numbers].
Code: Select all
SETLOCAL ENABLEDELAYEDEXPANSION
:: some commands..
:: curl path is !curl_p!
IF "!URL!" == "!URL:PostView.com?=!" IF "!URL!" == "!URL:PostList.com?=!" (
IF DEFINED URL_logNo (
ECHO ERROR
CALL :ERROR
EXIT /B
)
FOR /F %%A IN ('"!cURL_p!\curl.exe" -s https://url.com ^| "!NCA_P!\sed.exe" -n "s/^categoryNo=.\([0-9]\+\).$/\1/p"') DO SET URL_categoryNo=%%A
)
Code: Select all
:: this code will excute: "!cURL_p!\curl.exe" -s https://url.com | "!NCA_P!\sed.exe" -n "s/^categoryNo=.\([0-9]\+\).$/\1/p"
IF . EQU . (FOR /F %%A IN ('"!cURL_p!\curl.exe" -s https://url.com ^| "!NCA_P!\sed.exe" -n "s/^categoryNo=.\([0-9]\+\).$/\1/p"') DO SET URL_categoryNo=%%A)
options for sed below should also be enclosed in double quote.
But For /f that starts/ends with double quote will not work as expected.
Code: Select all
IF . EQU . (FOR /F %%A IN ('!cURL_p!\curl.exe -s https://url.com ^| "!NCA_P!\sed.exe" -n "s/^categoryNo=.\([0-9]\+\).$/\1/p"') DO SET URL_categoryNo=%%A)
Code: Select all
IF . EQU . (FOR /F %%A IN ('""!cURL_p!\curl.exe" -s https://url.com | "!NCA_P!\sed.exe" -n "s/^categoryNo=.\([0-9]\+\).$/\1/p""') DO SET URL_categoryNo=%%A)
Using CMD /C or moving to curl path is a not bad way, but I don't want to modify this code as much as possible.
Is there a simple way to use For /f that starts and ends with double quotes?