Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Batch file 带有xcopy的批处理条件语句_Batch File_Xcopy - Fatal编程技术网

Batch file 带有xcopy的批处理条件语句

Batch file 带有xcopy的批处理条件语句,batch-file,xcopy,Batch File,Xcopy,如果复制失败,我需要向提交者发送电子邮件。例如,我的代码如下: echo F|xcopy“%src_dir%”“%tgt_dir%”1>>“%logfile%”2>&1 echo成功:已成功升级Polysystems目录。1> >%logfile%”2>&1 我的输出是: 未找到文件-LTCG_v2306_02_07_2014_854.pfd 已复制0个文件 成功:已成功升级Polysystems目录 如果返回“未找到文件”,我需要发送失败电子邮件,而不是成功电子邮件。有没有办法将此消息存储在一

如果复制失败,我需要向提交者发送电子邮件。例如,我的代码如下:

echo F|xcopy“%src_dir%”“%tgt_dir%”1>>“%logfile%”2>&1

echo成功:已成功升级Polysystems目录。1> >%logfile%”2>&1

我的输出是:

未找到文件-LTCG_v2306_02_07_2014_854.pfd

已复制0个文件

成功:已成功升级Polysystems目录


如果返回“未找到文件”,我需要发送失败电子邮件,而不是成功电子邮件。有没有办法将此消息存储在一个变量中以与之进行比较?或者另一种方法来实现这一点?

您不应该存储消息,因为无法保证它会保持不变。 使用退出代码:

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%

有道理。在此上下文中,我将如何使用退出代码?复制失败时,脚本将在几行之后退出,代码为0,或成功。-对于我上面设置的示例,它将返回1,但它在哪里,所以我可以将代码用于我的条件语句?