VB脚本无法识别实际参数 [英] VB Script does not recognize the actual parameter

查看:138
本文介绍了VB脚本无法识别实际参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个VB脚本.说 First.vbs Second.vbs .

I've two VB Scripts. Say First.vbs and Second.vbs.

Frist.vbs 调用 Second.vbs .

我正在尝试使用以下代码将两个参数从 Frist.vbs 发送到 Second.vbs :

I am trying to send two parameters from Frist.vbs to Second.vbs using the following code:

First.vbs 的内容:

Set objShell = Wscript.CreateObject("WScript.Shell")
param1 = "Welcome"
param2 = "Gokul Nath"
objShell.Run "Second.vbs" & " " & param1 & " " & param2
Set objShell = Nothing

Second.vbs 的内容:

param1= Wscript.Arguments.Item(0)
param2 = Wscript.Arguments.Item(1)
WScript.Echo(param1)
WScript.Echo(param2)

我收到以下回声消息:

Welcome - Which is correct, since I've passed "Welcome" from First.vbs
Gokul - Which is WRONG, since I've passed "Gokul Nath" from First.vbs

会发生此问题,因为每个空格都被视为参数的结尾.

This issue occurs, since each space is considered as end of a parameter.

我是脚本新手,任何人都可以提出一些建议/参考.

I am new to scripting, can anyone give some suggestion/reference.

推荐答案

param2的值包含一个空格,您没有将参数放在双引号之间.因此,您的Run命令行实际上具有3个参数:

The value of param2 contains a space and you didn't put the parameter between double quotes. Because of that your Run command-line effectively has 3 arguments:

  • 欢迎
  • Gokul
  • 没事

为避免这种情况,请在第二个参数周围加上双引号:

To avoid that add double quotes around your second argument:

objShell.Run "Second.vbs" & " " & param1 & " """ & param2 & """"

更好的是,引用所有 参数并使用引号功能,以免被双引号淹没:

Better yet, quote all arguments and use a quoting function so you don't drown in double quotes:

Function qq(str)
  qq = Chr(34) & str & Chr(34)
End Function

objShell.Run "Second.vbs" & " " & qq(param1) & " " & qq(param2)

这篇关于VB脚本无法识别实际参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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