Re: Returning a value from a VBScript
- From: Tom Lavedas <tglbatch@xxxxxxx>
- Date: Thu, 13 Sep 2007 16:15:46 -0000
On Sep 13, 11:06 am, Matthias Tacke <Matth...@xxxxxxxx> wrote:
Pegasus (MVP) wrote:
"thecomputerguy74" <rgbl...@xxxxxxxxx> wrote in message
news:1189682751.346860.293120@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
I have searched the web for this, and maybe I'm using the wrong search
terms. I am trying to figure out how to return a value from my
VBScript for use by another script, batch file, or other command. All
I ever seem to find is how to return a value from a function, which
does me now good.
Any help would be appreciated. I'm sure it's not difficult, but I
don't know how to do it.
Thank you.
thecomputerguy74
Try this extremely simplified example:
@echo off
MyScript.vbs
echo MyScript.vbs returned an ErrorLevel of %ErrorLevel%
MyScript.vbs could contain this line:
WScript.Quit(2007)
If you need more digits as errorlevel allows (AFAIK 16 bit signed integer)
you can parse standard output of cscript in a batch:
@echo off
echo wscript.echo date-1>tmp.vbs
for /f %%a in ('cscript tmp.vbs //Nologo') do set "yesterday=%%a"
echo Yesterday=%yesterday%
DEL tmp.vbs
This task is much more complicated in pure batch (albeit possible)
--
Greetings
Matthias
In addition to the use of the exit code (Errorlevel) and the FOR
statement in Batch, I can think of at least four other approaches:
1). Write the data from the 'called' script into a temporary file to
be read by the 'calling' script - possibly using the exit code as a
suffix to a predetermined file name to keep old data from being
accessed.
2). Use the WScript.SHELL Exec method to run the 'called' script and
then collect its output stream. This is a variation on the approach
in 1 above that does not require a file, but its more complicated.
2). Use the system's clipboard. This approach is somewhat complicated
by the advent of IE 7, which added a security setting that needs to be
changed for this to work. Two enabling subroutines for this are ...
' Requires IE v5.0+
sub putClipBoardText5(sText)
With CreateObject("InternetExplorer.Application")
.Navigate "about:blank"
Do Until .ReadyState = 4 : WScript.Sleep 50 : Loop
.document.ParentWindow.ClipboardData.SetData "text", sText
end with ' IE
End Sub
' Requires IE v5.0+
Function getClipBoardText5()
With CreateObject("htmlfile")
On Error Resume Next
getClipBoardText5 = .ParentWindow.ClipboardData.GetData("text")
end with ' htmlfile
End Function
3). Use Michael Harris' IEPipe approach. Once this rather
complicated approach is understood, it permits the passing multiple
values of varying data type, even arrays and objects. Do a
google.groups search for Harris as the author and IEPipe as the key
word for information.
Tom Lavedas
===========
http://members.cox.net/tglbatch/wsh/
.
- References:
- Returning a value from a VBScript
- From: thecomputerguy74
- Re: Returning a value from a VBScript
- From: Pegasus \(MVP\)
- Re: Returning a value from a VBScript
- From: Matthias Tacke
- Returning a value from a VBScript
- Prev by Date: script namespace error
- Next by Date: Re: Trouble with xcacls in usercreation
- Previous by thread: Re: Returning a value from a VBScript
- Next by thread: help writting script to copy file to every desktop
- Index(es):
Relevant Pages
|