1
     main.bat contains:
     cscript treat.vbs /a:"the name of file"  

REm: the name of file contains many spaces

     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

When running the main.bat, msgbox shows a popup with all the name file (including all spaces contained within the name of file, while the echo message echo %1 shows the name of file cutting down.

How can I do to workaround that, please?

new
  • 1,109
  • 5
  • 21
  • 30

2 Answers2

2

Your problem seems to be "Call a bat from a vbs with parameters"

You dim param but use param_input

dim param: param_input=Wscript.Arguments.Named("a")

Your concatenation of the cmd to .run is faulty:

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

One way of getting it right is using and replacing ' with " to avoid VBScript's "" escape in concatenations:

>> 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"

For discussion/other ways see How-To-Quote-Like-A-Pro.

Ekkehard.Horner
  • 38,498
  • 2
  • 45
  • 96
1

You need to enclose the parameters to double-quotes to make the space be part of the parameter. And you need to escape those double-quotes by doubling them in VBS.

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

I could not include whole example, as you code does not even compile.

Refer also to question Adding quotes to a string in VBScript.

Community
  • 1
  • 1
Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992