您不能对外部进程使用异常处理(这是什么robocopy.exe
).
相反,您应该使用它$LASTEXITCODE
来确定执行的状态.每个单独的外部命令都有不同的退出代码,这意味着不同的东西(尽管0
几乎普遍意味着成功).
有关处理外部错误的信息,请参见此处的最后一节.
此处提供了robocopy退出代码列表,并提供以下信息:
0 No errors occurred and no files were copied. 1 One of more files were copied successfully. 2 Extra files or directories were detected. Examine the log file for more information. 4 Mismatched files or directories were detected. Examine the log file for more information. 8 Some files or directories could not be copied and the retry limit was exceeded. 16 Robocopy did not copy any files. Check the command line parameters and verify that Robocopy has enough rights to write to the destination folder.我强烈建议您将/ LOG参数与Robocopy一起使用,以便创建该过程的完整日志文件.这个文件对于找出问题是非常宝贵的.