Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I escape double quotes on command line to .vbs script?

I have a script. I want to send a line with double quotes inside it to that script, like this: Cscript myScript.vbs "Testing "this line""

But the double quotes inside the line make it so the line never gets to the script properly. I've tried escaping with a carat (^) or using double double-quotes ("Testing ""this line""") with different results, but none is the result I want (the script getting Testing "this line").

To justify why I need to do this, I'm trying to send an SQL line to a script that will edit my Orca table, and there needs to be double quotes in one of the values to do what I want to do with Orca.

like image 848
Tracy Avatar asked Jun 28 '11 20:06

Tracy


2 Answers

You could try this:

Here is the vb script x.vbs:

Wscript.Echo Unescape(Wscript.Arguments.Item(0))

Here is the output for running it:

D:\>cscript x.vbs "Testing %22this line%22"
Microsoft (R) Windows Script Host Version 5.8
Copyright (C) Microsoft Corporation. All rights reserved.

Testing "this line"

If you replace all " with %22 you will be able to use this method to pass the double quotes in.

like image 123
Jeremy E Avatar answered Oct 06 '22 00:10

Jeremy E


This cannot be done. I have tried everything and the only way to make this work is to designate some string of characters to represent " in your VBS and replace the command line arguments instance of the designated string with ". I picked something that would not likely be a problem :!: was the string i used to represent ".

In my code, I added the following:

strArgu0 = Wscript.Arguments(0)
strOldSTR = Replace(strArgu0,":!:","""")
like image 33
Sidney Hale Avatar answered Oct 05 '22 22:10

Sidney Hale