将值从 vbscript 传递到批处理 [英] pass value from vbscript to batch
问题描述
我有两个文件:batch.bat 和 vbscript.vbs..bat 文件包含一个循环,我需要在其中调用 .vbs,向它传递 2 个参数..vbs 文件包含一个带有 2 个参数的函数(我传递给 .vbs 文件的参数).我需要在 .bat 文件中访问我在 .vbs 中的函数返回的值.
有人可以帮我吗?
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?
我不是专家,所以请原谅我糟糕的语法.我正在调用 .bat 文件.文件应该看起来像这样
I am not an expert so please excuse my poor syntax. I am calling the .bat file. The files should look something like this
批处理文件:
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 :
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
'
推荐答案
UPDATED
好的,所以你需要返回一个非整数.下面的代码适用于非整数和文本.
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.
在您的 VB 脚本中,执行以下操作:
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%
这篇关于将值从 vbscript 传递到批处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!