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,为什么?
答案 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"