Consider the following:
// Calling-Script.ps1
Write-Output "Calling script"
./Failing-Script.ps1
Write-Output "Calling script again"
// Failing-Script.ps1
Write-Output "Failing script"
$ErrorActionPreference="stop"
Copy-Item invalid_file invalid_directory
Write-Output "Failing script again"
// output
Calling script
Failing script
Notice that Calling script again
didn't show up. First I thought that somehow the change of ErrorActionPreference
in Failing-Script.ps1
affected the one in Calling-Script.ps1
, but I checked it and it doesn't:
// Calling-Script.ps1
Write-Output "Calling script"
$ErrorActionPreference
./Failing-Script.ps1
Write-Output "Calling script again"
$ErrorActionPreference
// Failing-Script.ps1
Write-Output "Failing script"
$ErrorActionPreference
$ErrorActionPreference="stop"
#Copy-Item invalid_file invalid_directory
Write-Output "Failing script again"
$ErrorActionPreference
// output
Calling script
Continue
Failing script
Continue
Failing script again
stop
Calling script again
Continue
The question is: Why is the execution of Calling-Script.ps1
stops? Does this make sense? is it documented?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…