每次进入块批处理脚本时,enabledelayedexpansion concat字符串

时间:2014-08-05 11:34:05

标签: arrays batch-file smtp string-concatenation

我有下面的代码,当控件进入它时,在命令提示符中打印(else代码)错误。但是我想要一个字符串,其中包含一个字符串中的所有错误(Concat之前的字符串),并使用该字符串发送邮件。 / p>

  @echo off
echo Working !!!
setlocal enabledelayedexpansion
for /f "delims=" %%a in ('type test.log ^| findstr "Queue_ID"') do (
   set $Line=%%a
   for /f "tokens=2 delims=^=," %%b in ('echo !$Line!') do (
      set $Value=%%b
      set $Value=#Queue_id!$Value: =!
      if not defined !$Value! (set !$Value!=1) else (echo Error with [!$Value!]) 
))
endlocal
echo Done !!!
Pause

和邮件发送代码是

S:\blat.exe -body " error_String came from else code" -subject "KSD Error" -tf %recipients% -server %smtpserver% -f %sender%

1 个答案:

答案 0 :(得分:0)

只有在出现错误时才会发送电子邮件:

  @echo off
echo Working !!!
setlocal enabledelayedexpansion
for /f "delims=" %%a in ('type test.log ^| findstr "Queue_ID"') do (
   set $Line=%%a
   for /f "tokens=2 delims=^=," %%b in ('echo !$Line!') do (
      set $Value=%%b
      set $Value=#Queue_id!$Value: =!
      if not defined !$Value! (set !$Value!=1) else (set $liste=!$Liste!,[!$Value!]) 
))

if defined $Liste (
  echo Error List : !$Liste!
  echo sending Mail...
  S:\blat.exe -body !$Liste! -subject "KSD Error" -tf %recipients% -server %smtpserver% -f %sender%)
endlocal
echo Done !!!
Pause