Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

up vote 1 down vote accepted

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%
share|improve this answer
    
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 Apr 26 '13 at 22:45
    
After a long walk with my dog I got another idea, please check it out. –  Endoro Apr 27 '13 at 2:00
1  
Thanks! I've found another method as well. If you use curl -g "http://ci.onarandombox.com/job/Multiverse-Core/lastStableBuild/api/xml?tree=art‌​ifacts[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=art‌​ifacts[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 Apr 27 '13 at 6:56

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.