Re: Returning a value from a VBScript



Pegasus (MVP) wrote:
"thecomputerguy74" <rgblois@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
.



Relevant Pages

  • Re: Persisting env vars in cmd windows
    ... But the piece de resistance was the "start" command, ... - Have all code for the one project in one single batch file. ... @echo off ... echo:: ERROR ERROR ERROR ERROR ...
    (microsoft.public.win2000.general)
  • Re: Batching Updates?
    ... If you batch run them, they will automatically wait for one to finish before ... Echo Applying IE 5.5 Post-SP2 Hotfixes to system. ... Echo Reboot to activate changed files. ... >>the network login script or a batch file run on the ...
    (microsoft.public.security)
  • Re: Returning a value from a VBScript
    ... VBScript for use by another script, batch file, or other command. ... echo MyScript.vbs returned an ErrorLevel of %ErrorLevel% ...
    (microsoft.public.scripting.vbscript)
  • Re: Very weird DOS error
    ... >I have a batch file used to sort lots and lots of files into various ... > @echo ERROR! ... Destination directory missing. ...
    (microsoft.public.windowsxp.general)
  • Re: why cant i get variable value?
    ... i call this bath file in another batch file. ... batch executes the statement using the value AT PARSE TIME. ... @ECHO OFF ...
    (microsoft.public.win2000.cmdprompt.admin)

Loading