On 02/10/2014 03:23 AM, Anton Shepelev wrote:
> I am trying to create a bat-script for an MSBuild
> Post-build event that would process the built assem-
> bly with Dotfuscator. Unfortunately, some of
> Dotfuscator's parameters cannot be supplied on the
> command line and must be passed via a config file.
> Not wanting to hard-code the path to that file, I
> want dynamically to create it in the current direc-
> tory, use it with Dotfuscator, and delete it after-
> wards.
Instead of messing with properly escaped strings it would be much easier
to create and maintain if you use something which behaves sort of like a
HERE doc. A CMD script may contain any kind of data -- even binary data
-- as long as the interpreter does not try to read and interpret parts
of the script which it won't understand. To ensure that the interpreter
does not go where you don't want it to be, precede that portion with a
'GOTO :EOF'.
To create an XML file from the script you could include it in the script
and precede each line with some string which will get filtered out. Then
in the script you use FINDSTR to search your script for lines beginning
with that string, process each line to remove the string, then write it
to the XML file.
:main
CALL :writeXML C:\dir\file.xml
GOTO :EOF
:writeXML <filename>
SET "filename=%~f1"
:: Zero the file in case it exists:
TYPE NUL:>"%filename%"
SET "docChar=`"
For /F "delims=" %%c in (
'TYPE %~f0^|FindStr /B /I /C:"%docChar%"'
) Do (
Set "line=%%c"
(Echo;!line:*%docChar%=!)>>"%filename%"
)
GOTO :EOF
:: BEGIN XML FILE
`<tagA>
` <tagB>
` </tagB>
`</tagA>
:: END XML FILE
I don't have Windows available so the above might need some work -- it
was pulled out of an old script and modified without being tested.
"%docChar%" might have to be hard-coded.
Frank