如果副本失败,我需要向提交者发送电子邮件。例如我的代码是:
echo F | xcopy"%src_dir%" "%tgt_dir%" 1 GT;>"%日志文件%" 2 - ;&安培; 1
echo Success:Polysystems Directory成功升级。 1 GT;>"%日志文件%" 2 - ;&安培; 1
我的输出是:
找不到档案 - LTCG_v2306_02_07_2014_854.pfd
0文件已复制
成功:Polysystems目录成功推广。
如果"找不到文件"返回我需要发送一封失败的电子邮件,而不是成功的电子邮件。有没有办法将此消息存储在变量中以与之进行比较?或另一种方法来完成这个?
答案 0 :(得分:2)
您不应存储消息,因为无法保证消息保持不变。 请改用退出代码:
0 - Files were copied without error.
1 - No files were found to copy.
2 - The user pressed CTRL+C to terminate xcopy.
4 - Initialization error occurred. There is not enough memory or disk space, or you entered an invalid drive name or invalid syntax on the command line.
5 - Disk write error occurred.
因此,在“找不到文件”的情况下,xcode将返回退出代码“1”。 然后你可以发送你的电子邮件。
例如,它可能是这样的 这可能是一个例子:set my_errorlevel=0
xcopy....
if ERRORLEVEL 1 (
set my_errorlevel=%errorlevel%
) else echo Success: Polysystems Directory was successfully promoted. 1>>"%logfile%" 2>&1
...
exit /b %my_errorlevel%