Discussion forum for all Windows batch related topics.
Moderator: DosItHelp
-
noprogrammer
- Posts: 36
- Joined: 29 Oct 2009 11:55
#1
Post
by noprogrammer » 08 Oct 2015 11:49
Hi,
I want to dynamically write an .ini file in order to exchange data with another program.
The content of the .ini file is:
[Section]
id=randomstring
version=number
...
My problem is writing the data pair
variable=content in one line.
I'm unsure how to handle and concatenate the two parts.
The first part is for instance:
And the second part is:
Code: Select all
type install.rdf | xml sel -N ... >>myfile.ini
(xml:
XMLStarlet)
I tried to work with both variables and EnableDelayedExpansion, without success.
Any suggestions?
-
Squashman
- Expert
- Posts: 4486
- Joined: 23 Dec 2011 13:59
#2
Post
by Squashman » 08 Oct 2015 11:57
Capture the out from your command first and then echo it to your file.
Code: Select all
FOR /F "delims=" %%G in ('type install.rdf ^| xml sel -N') do >>myfile.ini echo id=%%G
I can't test this as I have no idea what the output of your XML command does.
-
noprogrammer
- Posts: 36
- Joined: 29 Oct 2009 11:55
#3
Post
by noprogrammer » 08 Oct 2015 12:32
Thank you. For better understanding I've attached the entire script (which doesn't work yet).
Code: Select all
@echo off
Echo [Extension] >ext.ini
For /f "delims=" %%e In ('type install.rdf ^| xml sel -N RDF=http://www.w3.org/1999/02/22-rdf-syntax-ns# -N em=http://www.mozilla.org/2004/em-rdf# -T -t --var "desc=/RDF:RDF/RDF:Description[@about]" -v "$desc/em:id"') Do >>ext.ini Echo id=%%e
For /f "delims=" %%f In ('type install.rdf ^| xml sel -N RDF=http://www.w3.org/1999/02/22-rdf-syntax-ns# -N em=http://www.mozilla.org/2004/em-rdf# -T -t --var "desc=/RDF:RDF/RDF:Description[@about]" -v "$desc/em:version"') Do >>ext.ini Echo version=%%f
For /f "delims=" %%g In ('type install.rdf ^| xml sel -N RDF=http://www.w3.org/1999/02/22-rdf-syntax-ns# -N em=http://www.mozilla.org/2004/em-rdf# -T -t --var "desc=/RDF:RDF/RDF:Description[@about]" -v "$desc/em:multiprocessCompatible"') Do >>ext.ini Echo multiprocessCompatible=%%g
I want to read out details for
uBlock Origin.
Instead of
type, I' intend to use
unzip in the final script, for instance:
Code: Select all
unzip.exe -pq ublock_origin-1.2.1-sm+fx+an.xpi install.rdf | xml sel -N RDF=http://www.w3.org/1999/02/22-rdf-syntax-ns# -N em=http://www.mozilla.org/2004/em-rdf# -T -t --var "desc=/RDF:RDF/RDF:Description[@about]" -v "$desc/em:id"
Currently the very first line is written (section), the rest is not.
-
Squashman
- Expert
- Posts: 4486
- Joined: 23 Dec 2011 13:59
#4
Post
by Squashman » 08 Oct 2015 14:04
Ok. So just running the command from the cmd prompt works fine.
Code: Select all
type install.rdf | xml sel -N RDF=http://www.w3.org/1999/02/22-rdf-syntax-ns# -N em=http://www.mozilla.org/2004/em-rdf# -T -t --var "desc=/RDF:RDF/RDF:Description[@about]" -v "$desc/em:id"
Output
-
Squashman
- Expert
- Posts: 4486
- Joined: 23 Dec 2011 13:59
#5
Post
by Squashman » 08 Oct 2015 14:18
Not quite sure why I can't capture the output with the FOR /F command but this works.
Code: Select all
@echo off
>ext.ini Echo [Extension]
<nul set /P ".=id=">>ext.ini
>>ext.ini (type install.rdf | xml sel -N RDF=http://www.w3.org/1999/02/22-rdf-syntax-ns# -N em=http://www.mozilla.org/2004/em-rdf# -T -t --var "desc=/RDF:RDF/RDF:Description[@about]" -v "$desc/em:id")
>>ext.ini echo.
<nul set /P ".=version=">>ext.ini
>>ext.ini (type install.rdf | xml sel -N RDF=http://www.w3.org/1999/02/22-rdf-syntax-ns# -N em=http://www.mozilla.org/2004/em-rdf# -T -t --var "desc=/RDF:RDF/RDF:Description[@about]" -v "$desc/em:version")
>>ext.ini echo.
<nul set /P ".=multiprocessCompatible=">>ext.ini
>>ext.ini (type install.rdf | xml sel -N RDF=http://www.w3.org/1999/02/22-rdf-syntax-ns# -N em=http://www.mozilla.org/2004/em-rdf# -T -t --var "desc=/RDF:RDF/RDF:Description[@about]" -v "$desc/em:multiprocessCompatible")
>>ext.ini echo.
pause
Output
Code: Select all
[Extension]
id=uBlock0@raymondhill.net
version=1.2.1
multiprocessCompatible=true
But I do not think you can pipe the contents of the install.rdf file straight from the unzip command. I think you will have to unzip it first and still use the TYPE command.
-
noprogrammer
- Posts: 36
- Joined: 29 Oct 2009 11:55
#6
Post
by noprogrammer » 09 Oct 2015 03:53
Set/p does the trick, thanks! Using UnZip 6.00 from 2009 piping the extracted rdf file works perfectly, too:
Code: Select all
<nul Set/p ".=id=">>ext.ini
>>ext.ini (unzip.exe -pq "uBlock0@raymondhill.net.xpi" install.rdf | xml sel -N RDF=http://www.w3.org/1999/02/22-rdf-syntax-ns# -N em=http://www.mozilla.org/2004/em-rdf# -T -t --var "desc=/RDF:RDF/RDF:Description[@about]" -v "$desc/em:id")
>>ext.ini echo.
I use another script to rename the downloaded add-ons to their id equivalents and resort to unzip to achieve that.
Next step will be the construction of the JSON object (with the help of
jq) to be stored in a config variable.
Thank you very much for your help!
-
Squashman
- Expert
- Posts: 4486
- Joined: 23 Dec 2011 13:59
#7
Post
by Squashman » 09 Oct 2015 07:05
noprogrammer wrote:Set/p does the trick, thanks! Using UnZip 6.00 from 2009 piping the extracted rdf file works perfectly, too:
Interesting. Will have to see if I can do that with Winzip as well. That might come in handy for an automation task I have been wanting to change for a few years.
-
Squashman
- Expert
- Posts: 4486
- Joined: 23 Dec 2011 13:59
#8
Post
by Squashman » 14 Oct 2015 09:51
Squashman wrote:noprogrammer wrote:Set/p does the trick, thanks! Using UnZip 6.00 from 2009 piping the extracted rdf file works perfectly, too:
Interesting. Will have to see if I can do that with Winzip as well. That might come in handy for an automation task I have been wanting to change for a few years.
Winzip can do it as well but does output some verbose information before it displays the file which is kind of annoying and I always have to pipe it to an arbitrary find command otherwise it seems to stop at the end of the file and not return control to the batch file.