1

I am facing the following issues while passing VBS user input paramaters to batch script:

  1. User input for two parameters are requested more than once to user
  2. Parameters are not passed to batch script

This is my script:

@echo off
setlocal EnableDelayedExpansion

>>usermessage.vbs ECHO WScript.Echo InputBox( "From_date", "para1", "DD-MMM-YYYY" )
>>usermessage.vbs ECHO WScript.Echo InputBox( "To_date", "para2", "DD-MMM-YYYY" )

set i=0

FOR /F "tokens=*" %%A IN ('CSCRIPT.EXE //NoLogo usermessage.vbs') DO (
  set /A i+=1
  SET para!i!=%%A
)

ECHO para1= %para1%
ECHO para2= %para2%

call path\name.bat '%para1%' '%para2% 23:59:59'

DEL usermessage.vbs

exit
4
  • The parameters should be passed to name.bat just fine, but your quoting is wrong. Single quotes are not valid quoting characters in batch scripts. Replace them with double quotes and try again. If it still doesn't work: show the content of name.bat and any error message you're getting. Dec 13, 2014 at 17:19
  • Thanks a lot Ansgar. It is working perfectly but parameters are requested to user more than thrice for both the parameters. Actually, it should request user only once for both the parameters. Please help me on this issue.
    – Jack
    Dec 13, 2014 at 18:46
  • 2
    >usermessage.vbs ... instead of the first >>usermessage.vbs ...
    – JosefZ
    Dec 13, 2014 at 19:25
  • Thanks JosefZ for highlighting the issue
    – Jack
    Dec 13, 2014 at 21:12

1 Answer 1

0

Only double quotes are valid quoting characters in batch scripts, not single quotes. Replace

call path\name.bat '%para1%' '%para2% 23:59:59'

with

call path\name.bat "%para1%" "%para2% 23:59:59"

and the parameters should be passed as you expect.

It might also be a good idea to change this:

>>usermessage.vbs ECHO WScript.Echo InputBox( "From_date", "para1", "DD-MMM-YYYY" )
>>usermessage.vbs ECHO WScript.Echo InputBox( "To_date", "para2", "DD-MMM-YYYY" )

into this:

>usermessage.vbs ECHO WScript.Echo InputBox( "From_date", "para1", "DD-MMM-YYYY" )
>>usermessage.vbs ECHO WScript.Echo InputBox( "To_date", "para2", "DD-MMM-YYYY" )

because the >> redirection operator appends to an already existing file instead of replacing it. If for some reason usermessage.vbs hasn't been deleted in the previous run, you'll get additional input dialogs. The > redirection operator truncates an already existing file, fixing this problem.

1
  • Thanks a lot Ansgar for helping me to close all my script issues.
    – Jack
    Dec 13, 2014 at 21:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.