Long story short: We receive a command from a script and want to execute it using windows shell.
Currently we use a method similar to:
echo start & command & echo finish
That works fine unless the command contains ampersands on its own, so for example
echo begin & if exist c:\temp.txt echo 1 & echo end will fail to write "end" if the file does not exist.
That can be solved by changing the command to
echo begin & (if exist c:\temp.txt echo 1) & echo end, but then we run into problems for commands that contain parentheses symbols, for example
echo begin & (echo %PATH%) & echo end prints "\Hewlett-Packard\HP was unexpected at this time." because I have Program Files (x86) in path.
Any way to escape special characters from the command's result?
Thanks in advance