1

我有两个文件:batch.bat 和 vbscript.vbs。.bat 文件包含一个循环,我需要在其中调用 .vbs,将 2 个参数传递给它。.vbs 文件包含一个带有 2 个参数的函数(我传递给 .vbs 文件的参数)。我需要在 .bat 文件中访问我在 .vbs 中的函数返回的值。
有人可以帮我吗?

我不是专家,所以请原谅我糟糕的语法。我正在调用 .bat 文件。这些文件应该看起来像这样

批处理.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
'
4

2 回答 2

7

更新

好的,所以你需要返回一个非整数。下面的代码适用于非整数和文本。

这是一个示例,您需要对其进行修改以满足您的需要。

在您的 VB 脚本中,执行以下操作:

WScript.Echo 99.99999

在您的批处理文件中,执行以下操作:

FOR /F "usebackq tokens=*" %%r in (`CSCRIPT "MyVBS.vbs"`) DO SET RESULT=%%r
ECHO %RESULT%
于 2013-07-26T12:16:14.870 回答
-2

使用环境变量作为批处理文件和 vbscript 文件参数传递之间的接口怎么样?

于 2013-07-26T11:55:17.573 回答