我无法理解这个位运算转换问题。
Robocopy退出代码与正常的0(成功),1(失败)模式不符,因此我想使用下面的powershell脚本包装我的robocopy调用,以使我的TeamCity构建配置在robocopy终止时失败或恰当进行。
第一个部分是使用网上的技巧解决的: ($LastExitCode -band 24)
正确地将退出代码8到16作为失败(1),所有其他代码作为成功(0)。
现在我想回显与退出代码相对应的消息。如何将整数退出代码(0-16)转换并四舍五入/向下取整为其十六进制等效项(0x00-0x10)?
param(
[string] $source,
[string] $target,
[string[]] $action = @("/MIR"),
[string[]] $options = @("/R:2", "/W:1", "/FFT", "/Z", "/XA:H")
)
$cmd_args = @($source, $target, $action, $options)
& robocopy.exe @cmd_args
$returnCodeMessage = @{
0x00 = "[INFO]: No errors occurred, and no copying was done. The source and destination directory trees are completely synchronized."
0x01 = "[INFO]: One or more files were copied successfully (that is, new files have arrived)."
0x02 = "[INFO]: Some Extra files or directories were detected. Examine the output log for details."
0x04 = "[WARN]: Some Mismatched files or directories were detected. Examine the output log. Some housekeeping may be needed."
0x08 = "[ERROR]: Some files or directories could not be copied (copy errors occurred and the retry limit was exceeded). Check these errors further."
0x10 = "[ERROR]: Usage error or an error due to insufficient access privileges on the source or destination directories."
}
Write-Host $returnCodeMessage[($LastExitCode <what goes here?>)]
exit ($LastExitCode -band 24)