-1

I'm struggling to call a command line correctly in VBS due to the \ escape character.

The string output I'm looking to write to the command line is,

batch_name=\"myBatch\"

Which gets passed to a .exe file. Unfortunately, due to the way the \ character works I can only write,

batch_name=\myBatch\
batch_name=\""myBatch\""

I can't get \" in the output! An altered version of my code is below,

BATCH_NAME = "myBatch"

outputString = "batch_name=\" & BATCH_NAME & "\"

I've tried lots of methods - Concatenating the string with Chr(34), using multiple double quotes, even trying to replace() "" with ", nothing seems to work.

Any ideas?

user2366626
  • 1
  • 1
  • 1

2 Answers2

1

I gave it a shot and

outputString = "batch_name=\""" & BATCH_NAME & "\"""

worked for me giving the result batch_name=\"myBatch\"

Does it work for you? How you execute this command in the shell?

misleadingTitle
  • 657
  • 6
  • 21
  • You are right, this works in a simple test environment, but it outputs \""myBatch\"" when run in the whole code. There must be something else in my code which is causing the error. Perhaps it's because BATCH_NAME is being passed as an argument from another .vbs file, and the string passed over has spaces? I don't have the file in front of me, but this line is part of a string of parameters passed over to another system, called through wscript.run() – user2366626 May 09 '13 at 17:47
  • 1
    Without more data (the passed argoument for example) or more code I'm afraid I can't help you. – misleadingTitle May 10 '13 at 08:03
1

You can do the following;

outputString = "batch_name=" & chr(92) & chr(34) & BATCH_NAME & chr(92) & chr(34)
Dan K
  • 409
  • 3
  • 12