将值从vbscript传递到批处理 [英] pass value from vbscript to batch

查看:60
本文介绍了将值从vbscript传递到批处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个文件: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

batch.bat:

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:

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

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆