批处理文件:Escape<和>在CALL参数?

时间:2014-12-04 18:38:08

标签: windows batch-file call

我有一个批处理文件,可以读取我可以转义的文本行,但这是必要的。

我需要将此文件部署到一个小型用户群,因此不能在每个人的PC上安装sed。

所以我一直试图用批处理文件来做这件事。

输入:

TAG1 GRfoo XY ^(as generated by Boolean^) minimum enclosed area ^(um2^) ^> ^= 0.10

...最终在这行代码中解析输入:

for /f "usebackq tokens=2*" %%i in (`echo %*`) DO (

...其中%*是通过CALL传递的参数:call:retTokenThreePlus !tagline!

我似乎试过逃避>:^>的每一个组合。 ^^^>,^^^^^>等等等。

我似乎无法弄清楚如何没有>从传递给:retTokenThreePlus方法的内容中消失。

谢谢!

批处理文件相关代码:

IF "%3"=="" (
  :: This monstrosity sets tagline to the FINDSTR result.
  for /f "usebackq tokens=*" %%a in (`FINDSTR /C:"TAG%2 " %tagfile%`) do set tagline=%%a
  call:retTokenTwo !tagline!
  set tagrule=!token!
  echo !tagline!
  call:retTokenThreePlus !tagline!
  set CMDLINE=!CMDLINE! !tagrule! !token!
  goto :write
)

:: Method to return only the second token of the parm list passed to it
:retTokenTwo
  set token=%2
  echo TOKEN2 %token%
  goto :eof

:: Method to return tokens 3+ of the parm list passed to it
:retTokenThreePlus
  REM setlocal enabledelayedexpansion
  for /f "usebackq tokens=2*" %%i in (`echo %*`) DO (
    set "token=%%j"
  )
  REM echo TOKEN3 !token!
  goto :eof

使用echo输出:

C:\gf28hpp\layout\icwinlp>set CMDLINE=$ 

C:\gf28hpp\layout\icwinlp>set token="" 

C:\gf28hpp\layout\icwinlp>IF "" == "" (
for /F "usebackq tokens=*" %a in (`FINDSTR /C:"TAG1 " block_checkdrc.tags`) do set tagline=%a  
 call:retTokenTwo !tagline!  
 set tagrule=!token!  
 echo !tagline!  
 call:retTokenThreePlus !!tagline!!  
 set CMDLINE=!CMDLINE! !tagrule! !token!  
 goto :write 
)  ELSE (
 ...[redacted]... 
) )  
) 

C:\gf28hpp\layout\icwinlp>set tagline=TAG1 GRfoo XY ^(as generated by Boolean^) minimum enclosed area ^(um2^) ^> ^= 0.10 

C:\gf28hpp\layout\icwinlp>set token=GRfoo 

C:\gf28hpp\layout\icwinlp>echo TOKEN2 GRfoo 
TOKEN2 GRfoo

C:\gf28hpp\layout\icwinlp>goto :eof 
TAG1 GRfoo XY ^(as generated by Boolean^) minimum enclosed area ^(um2^) ^> ^= 0.10

C:\gf28hpp\layout\icwinlp>REM setlocal enabledelayedexpansion 

C:\gf28hpp\layout\icwinlp>for /F "usebackq tokens=2*" %i in (`echo TAG1 GRfoo XY (as generated by Boolean) minimum enclosed area (um2) `) DO (set "token=%j" ) 

C:\gf28hpp\layout\icwinlp>(set "token=XY (as generated by Boolean) minimum enclosed area (um2) " ) 

C:\gf28hpp\layout\icwinlp>REM echo TOKEN3 !token! 

C:\gf28hpp\layout\icwinlp>goto :eof

0 个答案:

没有答案