I've been sitting here for 3 days now trying to solve the following problem.
I need a call function that I can pass a url as a parameter to. However, this URL has an &, which no longer works as soon as I pass the variable as a call parameter.
I can't set /& in the Url, because its a dynamic Url.
Every url begins with https:// and ends with &dl=1
@echo off
setlocal enabledelayedexpansion
set "url=!array[2]!"
call :do_download
:do_download
powershell -c "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12;
Invoke-WebRequest '%url%' -OutFile 'C:\Program Files (x86)\test.zip'"
But if i try in all versions of quotes, doublequotes, with trimm or other tricks, it dont work :´( I have rly no idea yet. But i need the Url as call-param.
@echo off
setlocal enabledelayedexpansion
set "url=!array[2]!"
call :do_download "%url%"
:do_download
powershell -c "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12;
Invoke-WebRequest '%1' -OutFile 'C:\Program Files (x86)\test.zip'"
If you try it self:
you can save a packs.txt with:
Testlink
https://sync.luckycloud.de/d/76ffff3d76ea4e9ab15e/files/?p=%2FTest.txt&dl=1
The link is to download a .txt file with 200 words from lorem ipsum.
and here is the complete code, that will work at this moment, but without call-param. you can set the paths whatever you want, it's only for example.
This code runs by itself; the ! are used because later it will be inside an if, but that code is independent of this one.
@echo off
setlocal enabledelayedexpansion
call :readtest
pause
call :do_download
pause
:readtest
set count=0
for /f "usebackq tokens=*" %%A in ("C:\Program Files (x86)\Steam\steamapps\common\packs.txt") do (
set /a count+=1
set url[!count!]=%%A
)
set "pack_sd=!url[2]!"
goto :eof
:do_download
powershell -c "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; Invoke-WebRequest '%pack_sd%' -OutFile 'C:\Program Files (x86)\Steam\steamapps\common\test.txt'"
goto :eof
If i try the answer with use: :"=
call :do_download "%pack_sd%"
:do_download
echo TT %1 TT
set "url=%1"
set test=%url:"=%
echo "TT %test% TT"
first echo:
TT "https://sync.luckycloud.de/d/76ffff3d76ea4e9ab15e/files/?p=FTest.txt&dl=1" TT
second echo:
error: command "dl" is wrong or unknown...
"TT "= TT"
If i try the answer with %~1
call :do_download "%pack_sd%"
:do_download
echo TT %1 TT
set url=%~1
echo "TT %url% TT%
first echo:
TT "https://sync.luckycloud.de/d/76ffff3d76ea4e9ab15e/files/?p=FTest.txt&dl=1" TT
second echo:
error: command "dl" is wrong or unknown...
"TT https://sync.luckycloud.de/d/76ffff3d76ea4e9ab15e/files/?p=FTest.txt TT"
if i use the answer with: '%1:"=' inside powershell command:
call :do_download "%pack_sd%"
:do_download
powershell -c "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; Invoke-WebRequest '%1:"=' -OutFile 'C:\Program Files (x86)\Steam\steamapps\common\test.txt'"
goto :eof
error: "The string has no terminator: '."