我对批处理编程和 vbscripting 很陌生
我想将变量从 vbscript 传递到批处理文件。 这是我的 vbscript 代码:
Dim shell,a
a="Hello World"
set shell=createobject("wscript.shell")
shell.run "test.bat a"
下面是我的批处理文件:
@Echo off
echo %1
PAUSE
我想要回显的结果是“Hello World”,但“a”是回显
最佳答案
您需要将命令行传递给 shell.run
以包含变量 a
的内容,而不仅仅是字母“a” “本身。
在您的 VBS 中尝试此操作:
Dim shell,a
a="Hello World"
set shell=createobject("wscript.shell")
shell.run "test.bat """ & a & """"
这将有效地使该行显示 shell.run "test.bat ""Hello World"""
。
在 VB(各种类型 - 脚本、.Net、VB6 等)中,您需要在字符串文字中放置两个双引号来转义其中一个。
唯一的问题是双引号将传递到您的批处理文件。
关于windows - 将变量从 vbscript 传递到批处理文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32130928/