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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Retun success or failure of script

Status
Not open for further replies.

TWillard

Programmer
Apr 26, 2001
263
US
I have a vbs script file that I am running on a command line. Is there anyway to return a success or failure of vbscript back to the calling command line.

For example, suppose the following is my vbs file.

test.vbs
---------
msgbox("hello")
xyz
---------


This script will cause an error on line xyz, b/c this is not valid vbscript syntax or command. If I run this vbs script from the command line c:\>test.vbs I notice several things.
1) The scripts starts and a hello msgbox is displayed
2) Almost instantly, a new blank command line is ready c:\>
3) The msgbox is still displaying, so I believe the script is still in execution mode
4) I click on the OK button and WSH error appears

Here is what I would like, ( if possible )
1) Execute script c:\>test.vbs
2) Command Line holds until script is finished, HOW???
3) Msgbox is displayed, life is good, click ok
4) New command line is ready for input


Any ideas?????


 
In a %COMSPEC% windows do a
Code:
 start /?
.

Hope This Help
PH.
 
I am not sure I understand. Could you provide more detail, perhaps the comand line call that I could use?

It sounds to me like I should run the following:

c:\>start test.vbs /?

But that does not work!
 
This snip of code seems to work fine!

c:\>start /WAIT test.vbs

I think it opens a seperate thread to process the program and the current command waits until that thread is complete.

I would still like to know if within the vbs script file itself, if there is any way to progamatically return a success???? Any ideas?

 
A vbs script can return a ErrorLevel with this syntax:
Code:
WScript.Quit(intReturnCode)

Hope This Help
PH.
 
Twillard,

I think this is what you are looking for.

Dim WshShell
Set WshShell = Wscript.CreateObject("Wscript.Shell")

on error resume next
set vbx = wshShell.exec ("cmd /E:eek:n /C Dir K:\ > c:\scripts\test.txt")
' Must store this in variable so next read doesn't clear it.
vartmp = vbx.stderr.readall
if vartmp <> &quot;&quot; then
msgbox err.number & &quot; &quot; & vartmp
end if

This script executes a &quot;DIR&quot; command of the &quot;K:&quot; drive which is non-existent. That forces an error. The vbx.stderr.readall will contain a string if an error exists.

fengshui_1998
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top