Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
520 views
in Technique[技术] by (71.8m points)

pass value from vbscript to batch

I have two files: batch.bat and vbscript.vbs. The .bat file contains a loop where I need to call the .vbs, passing to it 2 arguments. The .vbs file contains a function with 2 arguments( the arguments I am passing to the .vbs file). I need to have access in the .bat file to the value my function in .vbs returns.
Could someone help me, please?

I am not an expert so please excuse my poor syntax. I am calling the .bat file. The files should look something like this

batch.bat :

loop start

' calling the vbs file

cscript vbscript.vbs arg1 arg2 ( here I suppose something has to be add to get val from vbs)

' using value returned by .vbs function

loop end 

vbscript.vbs :

function myfunction(arg1,arg2)
dim value

' do some calculation

myfunction= value
end function

dim value_to_return_to_batch
' now calling the function
value_to_return_to_batch=myfunction(arg1,arg2)
'
' here something has to be add to send value_to_return_to_batch  to batch
'
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

UPDATED

Ok, so you need to return a non-integer. The code below will work for non-integers as well as text.

This is an example, you will need to modify it to fit your needs.

In your VB Script, do this:

WScript.Echo 99.99999

In your batch file, do this:

FOR /F "usebackq tokens=*" %%r in (`CSCRIPT "MyVBS.vbs"`) DO SET RESULT=%%r
ECHO %RESULT%

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...