#1
|
|||
|
|||
Exit VBScript
I'm writing a VBScript step, and need to exit the script prematurely. However, WScript.Quit is not supported. So, how does one exit a script?
Rob |
#2
|
|||
|
|||
Use structured programming or put your code in a subroutine and exit the subroutine:
MySub ' call the subroutine Sub MySub() ' some code Exit Sub ' some more code End Sub |
#3
|
|||
|
|||
So what you're really saying is that there is no way to exit a script, the script 'code' must completely execute. If I want to stop execution, I have to enclose the entire remainder of the script inside an 'If' test...
BTW, putting code in a subroutine and using the sub's 'Exit Sub' call does not shutdown a script, it merely exits the subroutine. |
#4
|
|||
|
|||
How would "exiting the script" be different from exiting the subroutine before the end? An Exit Sub statement within a subroutine prevents the remainder of the subroutine code from executing, which has the same effect as calling WScript.Quit in a .vbs file (preventing the remainder of the code in the .vbs file from executing).
|
#5
|
|||
|
|||
Actually, the VBP online help says this about WScript:
A helper object to provide compatibility with WSH script code. It's actually an alias for the Builder object, so all methods on each object are available on both. So, that means that the .Quit method is supposed to be available, right? |
#6
|
|||
|
|||
Actually, only the WScript CreateObject, Sleep, and Echo methods are supported (we'll update the docs to be explicit about that). But, again, there are other ways to exit a script "prematurely." Also, if you want to stop the build with an error from within script code, use
Err.Raise 1, Step.Name, "error description" |
|
|