I am running a vbs script from inside a batch file, and I need the
return code (or any other way to get some return value returned):
...
d:\test.vbs //B
echo %errorlevel%
...
but even if test.vbs returns 10, %errorlevel% is always 0.
probalby because internally "cscript d:\test.vbs //B" is used, and
cscript returns 0 ?
so how can I get my value from within the vbs script?
Tom Lavedas
============
http://members.cox.net/tglbatch/wsh/
An extract from
182662 Jan 13 2007 ftp://garbo.uwasa.fi/pc/link/tscmd.zip
tscmd.zip Useful NT/2000/XP script tricks and tips, T.Salmi
With Visual Basic Script one can have
@echo off & setlocal enableextensions
:: Make a temporary folder
if not exist c:\mytemp mkdir c:\mytemp
::
:: Set the errorlevel
echo WScript.Quit ^5>c:\mytemp\tmp$$$.vbs
cscript //nologo c:\mytemp\tmp$$$.vbs
::
for %%e in (0 1 2 3 4 5 6 7 8 9) do (
if %errorlevel% EQU %%e echo The errorlevel is %%e)
::
:: Clean up
for %%f in (c:\mytemp\tmp$$$.vbs) do del %%f
rmdir c:\mytemp
endlocal & goto :EOF
The output will be
D:\TEST>cmdfaq
The errorlevel is 5
All the best, Timo
--
Prof. Timo Salmi ftp & http://garbo.uwasa.fi/ archives 193.166.120.5
Department of Accounting and Business Finance ; University of Vaasa
mailto:t...@uwasa.fi <http://www.uwasa.fi/~ts/> ; FIN-65101, Finland
Timo's FAQ materials at http://www.uwasa.fi/~ts/http/tsfaq.html
Note, the //B is not required to use .vbs from within a batch. It only
suppresses output and prompts from being displayed. The problem has nothing
to do with host selection, its your method of calling it. Typically we
explicitly call the command line host.
cscript /nologo d:\test.vbs
But the wscript.exe host does return an exit code too. To see it you must
tell the batch to wait for the script to finish, otherwise the batch moves
to the next line before the scripting host even loads.
start /wait d:\test.vbs
-or-
start /wait wscript d:\test.vbs
--
Todd Vargo
(Post questions to group only. Remove "z" to email personal messages)
I see that you are still writing here :-)
Today I wanted an errorlevel to see if it's a file or folder or
something else.
I got two solutions both not using VBS, but I can't figure out what one
is best.
@echo off& setlocal enableextensions enabledelayedexpansion
call:isFile "%~1"& if errorlevel 1 goto:eof
As you can see, I only want a file. The rest of my program goes here...
...
goto:eof
Solution 1:
:isFile "X"
set a=%~a1& if "!a:~,1!"=="-" (color 07) else color 11
goto:eof
rem from source/based on this:
(set a=%~a1)
if "%a:~,1%" == "-" (
echo file.
) else (
if "%a:~,1%" == "d" (echo folder ^(path^).
) else echo not a file.
)
goto:eof
Solution 2:
:isFile "X"
if exist "%~1\" (color 11) else if exist "%~1" (color 07) else color
11
goto:eof
rem from source/based on this:
if exist "%~1\" (echo folder ^(path^), or empty.) else if exist "%~1"
(
echo file.) else echo not a file.
goto:eof
Benny,
PS. Todd, I was/(is) here:
My gallery no 1: http://hjem.get2net.dk/b_pedersen/gallery/gallery.htm
My gallery no 2:
http://www.photoshopelementsuser.com/gallery/view_img.php?id=11820
btw. Todd, try a click on a url with the midle mouse button (click with
the mouse wheel) in the new IE7...
:-)
my name.p...@gmail.commmm
Todd Vargo wrote:
> "Arcane" <yo...@arcor.de> wrote in message
> news:1168958417....@l53g2000cwa.googlegroups.com...
> > Hi
> >
> > I am running a vbs script from inside a batch file, and I need the
> > return code (or any other way to get some return value returned):
> >
...Snip...
Beauty is in the eye of the beholder. ;-)
snip...
> Benny,
> PS. Todd, I was/(is) here:
> My gallery no 1: http://hjem.get2net.dk/b_pedersen/gallery/gallery.htm
> My gallery no 2:
> http://www.photoshopelementsuser.com/gallery/view_img.php?id=11820
>
> btw. Todd, try a click on a url with the midle mouse button (click with
> the mouse wheel) in the new IE7...
> :-)
IE7 does not install on Window 98, just as well, I don't like it.
BTW, nice photos (and your #1 web scripting is interesting too).