SETLOCAL ENABLEDELAYEDEXPANSION , Interrupt SETLOCAL ENABLEDELAYEDEXPANSION, SETLOCAL ENABLEDELAYEDEXPANSION

本秂侑毒 提交于 2019-12-13 09:52:35

问题


NOTE:THIS IS NOT A DUPLICATE!! OF "Temporarily interrupt SETLOCAL"

i want to be able to SETLOCAL ENABLEDELAYEDEXPANSION then do something, then ENDLOCAL ENABLEDELAYEDEXPANSION do something else (7z command) then SETLOCAL ENABLEDELAYEDEXPANSION once again in a .bat! because 7z.exe does not allow SETLOCAL ENABLEDELAYEDEXPANSION. see?

code:

SETLOCAL ENABLEDELAYEDEXPANSION
Echo hi!
7z e -o"C:\test" -i!*.jar "C:\*.zip"

output:
hi!
Error: incorrect command line

when i change my code to:

Echo hi!
7z e -o"C:\test" -i!*.jar "C:\*.zip"

it works!!!!!!

here is my code so far to interrupt SETLOCAL ENABLEDELAYEDEXPANSION, unfortunately it doesn't work.

SETLOCAL ENABLEDELAYEDEXPANSION
Echo hi!
Endlocal
7z e -o"C:\test" -i!*.jar "C:\*.zip"
SETLOCAL ENABLEDELAYEDEXPANSION
Echo hi!

i want to put this in a different .bat which needs SETLOCAL ENABLEDELAYEDEXPANSION to run


回答1:


You may solve your problem this way:

set bang=!
SETLOCAL ENABLEDELAYEDEXPANSION
Echo hi!
7z e -o"C:\test" -i!bang!*.jar "C:\*.zip"

Just be sure that the set bang=! command is executed when delayed expansion is disabled.




回答2:


7zip hasn't problems with delayed expansion.
It's the exclamation mark, it will be removed from the line before 7z see it.

You only need to escape them.

SETLOCAL ENABLEDELAYEDEXPANSION
Echo hi^^!
7z e -o"C:\test" -i^^!*.jar "C:\*.zip"


来源:https://stackoverflow.com/questions/18422082/setlocal-enabledelayedexpansion-interrupt-setlocal-enabledelayedexpansion-set

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!