0

I've got this code in vbscript that launches a batch script with some arguments.

CreateObject("WScript.Shell").Run "printTR.bat " & jsfunction() & " " & amount & " " & printer

The problem is, sometimes the jsfunction() has spaces, so as you could see the 2nd word would be counted as nother variable. I've tried things like """ & jsfunction() & """" and """ & jsfunction() & """, which stopped the script from working at all.

The jsfunction() is basically just a return of a user input field in the same page. It could contain anything that can be typed on a keyboard.

How can I pass the variable as a single string?

3
  • I disagree with the close requests as I have given all the information I know how to gather about the issue. I'm not asking why the code isn't working, and I provided the steps I tried to fix it and the code causing problems. Feb 10, 2017 at 19:10
  • So we are just supposed to guess what jsfunction() does as Alex has done in their answer? - "assuming jsfunction() does not itself return a string that contains quotes". So, because you don't provide enough information people are left to second guess you.
    – user692942
    Feb 11, 2017 at 12:51
  • @Lankymart I didn't know that was important. That could have easily been asked in the comments and I would have added it to the post. Feb 11, 2017 at 16:05

1 Answer 1

1
CreateObject("WScript.Shell").Run "printTR.bat """ & jsfunction() & """ " & amount & " " & printer

Is the correct way to pass the string with quotes (assuming jsfunction() does not itself return a string that contains quotes) .

If that fails perhaps its because the batch file now also received the string with quotes (echo %1 would return "a quoted string") where is does not expect to, to rectify this use %~1 which is the same string but without quotes.

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