Parameters 使用参数从bat调用bat

Parameters 使用参数从bat调用bat,parameters,vbscript,batch-file,Parameters,Vbscript,Batch File,REm:文件名包含许多空格 main.bat contains: cscript treat.vbs /a:"the name of file" 运行main.bat时,msgbox会显示一个包含所有文件名(包括文件名中包含的所有空格)的弹出窗口,而回显消息echo%1会显示文件名 请告诉我如何解决这个问题?您的问题似乎是“使用参数从vbs调用bat” 您调暗param但使用param\u输入 treat.vbs contains: dim para

REm:文件名包含许多空格

     main.bat contains:
     cscript treat.vbs /a:"the name of file"  
运行main.bat时,msgbox会显示一个包含所有文件名(包括文件名中包含的所有空格)的弹出窗口,而回显消息echo%1会显示文件名

请告诉我如何解决这个问题?

您的问题似乎是“使用参数从vbs调用bat”

您调暗
param
但使用
param\u输入

     treat.vbs contains:
     dim param: param_input=Wscript.Arguments.Named("a")
     msgbox param_input
     shell.run "second.bat" param_input & " " & ""myfile.out""

     second.bat contains:(just for purpose of test)
     echo %1
     echo %2
将cmd连接到.run时出错:

dim param: param_input=Wscript.Arguments.Named("a")
一种正确的方法是使用“并替换为”以避免VBScript在串联中的“转义”:

>> s = "second.bat" param_input & " " & ""myfile.out""
>>
Error Number:       1025
Error Description:  Expected end of statement

有关讨论/其他方法,请参见。

您需要将参数用双引号括起来,使空格成为参数的一部分。您需要通过在VBS中将双引号括起来来转义这些双引号

>> param_input = "the name of file"
>> s = Replace("'second.bat' '" & param_input & "' 'myfile.out'", "'", """")
>> WScript.Echo s
>>
"second.bat" "the name of file" "myfile.out"
我不能包含整个示例,因为您的代码甚至不编译

另请参阅问题

shell.run "second.bat """ & param_input & """ ""myfile.out"""