退出代码没有冒出来

时间:2015-02-25 14:45:44

标签: powershell powershell-v4.0

Outer.ps1:

& "$env:WINDIR\syswow64\WindowsPowerShell\v1.0\powershell.exe" -NonInteractive -NoProfile -ExecutionPolicy Bypass -Command "& '.\Inner.ps1'; Write-Host "BLOCK: $LastExitCode"; exit $LastExitCode"
Write-Host "OUTSIDE: $LastExitCode"

Inner.ps1:

exit 3

执行Outer.ps1输出:

BLOCK: 1
OUTSIDE: 1

什么,为什么? Inner.ps1明显退出退出代码3.问题是什么?

注意:如果我将Inner.ps1更改为返回0,我会收到以下输出:

BLOCK: 0
OUTSIDE: 0

不知何故,0以外的所有其他代码默认为1,为什么?

1 个答案:

答案 0 :(得分:4)

你有引用问题:

& "$env:WINDIR\syswow64\WindowsPowerShell\v1.0\powershell.exe" -NonInteractive -NoProfile -ExecutionPolicy Bypass -Command '& ''.\Inner.ps1''; Write-Host "BLOCK: $LastExitCode"; exit $LastExitCode'
Write-Host "OUTSIDE: $LastExitCode"