Why doesn't my script work?

0

The script I am using is
FOR /F "tokens=91 delims=<>" %%v IN ('curl http://ci.onarandombox.com/job/Multiverse-Core/lastStableBuild/api/xml') DO ECHO %%v
What I want it to do is search the output of
curl http://ci.onarandombox.com/job/Multiverse-Core/lastStableBuild/api/xml
(copy and paste the url to see it. in command prompt, the command puts it's all on one line though)
for <artifact><displayPath> **THIS BIT HERE** </displayPath> and echo the result. When I run it, however, it displays the cURL downloading info, but doesn't echo anything at all. What do I need to change in my script?

Craft1n3ss

Posted 2013-04-26T12:05:43.127

Reputation: 67

Answers

1

The issue is "tokens=91", the maximum allowed token number is 31. You need a special technique to deal with such xml files with over 3000 chars per line in batch. This technique is beyond the scope of an answer at SU.

BTW: if you want to check out the max number of tokens you can use the following code:

@echo off &setlocal enabledelayedexpansion
set /a maxtok=40
set /a curtok=0

for /l %%i in (1,1,%maxtok%) do set "tokvar=!tokvar! %%i"
echo variable with tokens: %tokvar%
:tokloop
set /a curtok+=1
set "disptok="
for /f "tokens=%curtok%" %%i in ("%tokvar%") do set "disptok=%%i"
echo %disptok% ^<-- there should be number %curtok%
if %curtok% lss %maxtok% goto :tokloop

Insted, you can try the following code after download the xml and put it in a file (file.xml):

@echo off &setlocal
set "xmlfile=file.xml"
set "prefix=<artifact><displayPath>"

for /f "delims=" %%i in (%xmlfile%) do if not defined xmlline set "xmlline=%%i"
setlocal enabledelayedexpansion
:xmlloop
set /a xmlcount+=1
set "xmlline=!xmlline:*%prefix%=!"
for /f "delims=<" %%i in ("%xmlline%") do set "line%xmlcount%=%%i"
if %xmlcount% lss 3 goto:xmlloop
echo %line1%
echo %line2%
echo %line3%

Endoro

Posted 2013-04-26T12:05:43.127

Reputation: 2 036

Thanks, I was wondering why it didn't work even though the command syntax was correct. I'll try making a script that'll delete the first 90 characters (in steps of 30) and post it here if I manage to get it working. – Craft1n3ss – 2013-04-26T22:45:36.427

After a long walk with my dog I got another idea, please check it out. – Endoro – 2013-04-27T02:00:27.813

1Thanks! I've found another method as well. If you use curl -g "http://ci.onarandombox.com/job/Multiverse-Core/lastStableBuild/api/xml?tree=artifacts[relativePath]", you'll just get the paths. Here's what I eventually got: FOR /F "tokens=14 delims=<>" %%a IN ('curl -g "http://ci.onarandombox.com/job/Multiverse-Core/lastStableBuild/api/xml?tree=artifacts[relativePath]"') DO ECHO url = "http://ci.onarandombox.com/job/Multiverse-Core/lastStableBuild/artifact/%%a" > Cache\Multiverse-Core.txt curl -z plugins\Multiverse-Core.jar -K Cache\Multiverse-Core.txt – Craft1n3ss – 2013-04-27T06:56:16.707