-
Notifications
You must be signed in to change notification settings - Fork 0
/
Object.ForEachAll.CMD
40 lines (35 loc) · 1.22 KB
/
Object.ForEachAll.CMD
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
::@author FB
::@version 0.1.0
::转义Powershell命令:
:: ^ ^^ | ^| & ^& < ^< > ^> % %% " """ ` ^` , ^, ; ^; = ^= ( ^( ) ^)
::回调遍历全部
:: 参数1: 实例名称
:: 参数2: 回调命令行
:: 仅支持能在单个参数传递的命令行.
:: 占位符: {0}键; {1}值;
:: 参数3: 变量名
:: 如果参数2为`-`时, 则参数3为保存回调命令行的变量名.
:: 退出码: 0,执行成功; N,失败次数;
::Script:Common.Clone.CMD::
::Script:Process.Callback.CMD::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
SET "@=0" & SET "@PREFIX=%~1."
IF "%~2" == "-" (CALL Common.Clone.CMD "%~3" "@CMD") ELSE (SET "@CMD=%~2")
FOR /F "usebackq delims=" %%A IN (
`Powershell.exe -NonInteractive -Command ^^^& {
$ErrorActionPreference ^= 'SilentlyContinue'^;
$Pattern ^= [Regex]::Escape^(${Env:@PREFIX}^) + '^(.+^)'^;
$Pattern ^= '^^^^' + $Pattern + '$'^;
$Items ^= Get-Item Env:${Env:@PREFIX}* ^^^| Sort-Object -Property Key^;
foreach ^($Item in $Items^) {
if ^($Item.Key -match $Pattern^) {
${Env:@CMD} -f $Matches[1]^,$Item.Value^;
}^;
}^;
}`
) DO (
SET "@CMD=%%A"
CALL Process.Callback.CMD - "@CMD" || SET /A "@+=1"
)
SET "@PREFIX=" & SET "@CMD="
EXIT /B %@%