Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Way to tell if called Script produced an error 2

Status
Not open for further replies.

Jooky68

Programmer
Jul 10, 2002
231
US
I am writing a script that calls another script. The script works fine but if the called script does not work correctly it will throw an error and than the calling script will continue to run. I wan the calling script to somehow throw an error if one of the called scripts produces and error

I call the script using the wscript.shell and calling the .run method. For example

test.run "cscript myscript.vbs",1,true

Does anyone have an idea of how I could get the calling script to notice if the called script produces and error? If I do not make changes to the script if the called script throws and error I will still get a successful change from my calling script. Thanks

 
Jooky68,

You might be able to do this another way, but I would set up an environment variable and pass it back and forth. This was an issue that had, and needed to pass variables back and forth from script A to script B, Process in Script B and then return to script A and continue the script. You could do that with error checking variables too.

You can read in this forum how I did that here:

Good Luck!!
-SWarrior
 
Jooky68,

To monitor the error (exit code) of a child vbscript process as spawned via .run, you have to make the necessary design in the vbscript being called upon---and this is normal as the scripter has full control at this stage. To transmit the error code, you pass it via the exit code at wscript.quit.

It may be a bit abstract here. Take a example. Suppose a parent.vbs calls a child.vbs. In the child.vbs, at critical place, you want to monitor the error. You pass the error code (built-in or custom-designed) with wscript.quit(exitcode). Then, this exitcode is retrievable from the .run return value.
Code:
'parent.vbs
sscriptfile="child.vbs"

'must be true (synchronous) else no good
iret=createobject("wscript.shell").run("cscript.exe //b //nologo  " & sscriptfile,1,true)
wscript.echo iret    'prove of concept
Code:
'child.vbs
on error resume next
f=1/0	'overfloat (11)
if err.number<>0 then
	wscript.quit (err.number)
end if
on error goto 0
regards - tsuji
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top