SETLOCAL ENABLEDELAYEDEXPANSION , Interrupt SETLOC

2019-10-05 07:21发布

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

2条回答
一夜七次
2楼-- · 2019-10-05 07:50

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"
查看更多
干净又极端
3楼-- · 2019-10-05 08:01

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.

查看更多
登录 后发表回答