运行PowerShell中的这里面的代码给出了奇怪的结果:为什么批处理退出代码在返回到PowerShell时发生了错误?
PS> .\test.bat; $lastexitcode
>exit /b 0
2
PS> cmd /c exit /b 0; $lastexitcode
0
有人能解释如何纠正该批处理文件的版本?我还想指出0
以外的退出值正常工作。
运行PowerShell中的这里面的代码给出了奇怪的结果:为什么批处理退出代码在返回到PowerShell时发生了错误?
PS> .\test.bat; $lastexitcode
>exit /b 0
2
PS> cmd /c exit /b 0; $lastexitcode
0
有人能解释如何纠正该批处理文件的版本?我还想指出0
以外的退出值正常工作。
所有这些解决方案的工作。如果有人可以解释我将不胜感激:
PS> & cmd.exe /c 'test.bat && exit'; $lastexitcode
>exit /b 0
0
PS> cmd.exe /c 'test.bat && exit'; $lastexitcode
>exit /b 0
0
我能够在PSV2使用exit /b <code>
重现,它显示为预期PSv3工作。对于PSv2,当我删除/b
这意味着When used in a batch script, this option will exit only the script (or subroutine) but not CMD.EXE
时,它开始按预期工作。
大约有PowerShell的报道处理退出码不正确的一些问题: https://connect.microsoft.com/PowerShell/SearchResults.aspx?SearchQuery=exit%2520code
我没有看到这个特别,但是这并不是说,它没有固定的PSv3。
批处理文件是做什么的? – MDMoore313 2013-04-25 14:00:11
第二行回显'exit/b 0' – cmcginty 2013-04-26 20:02:04