简体   繁体   English

如何在命令行 to.vbs 脚本上转义双引号?

[英]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""我想将其中包含双引号的行发送到该脚本,如下所示: 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").我试过 escaping 与克拉 (^) 或使用双双引号 ("Testing ""this line""") 得到不同的结果,但没有一个是我想要的结果(脚本正在测试“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.为了证明我为什么需要这样做,我试图将 SQL 行发送到将编辑我的 Orca 表的脚本,并且需要在其中一个值中使用双引号来执行我想要对 Orca 执行的操作。

You could try this:你可以试试这个:

Here is the vb script x.vbs:这是 vb 脚本 x.vbs:

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

Here is the output for running it:这是用于运行它的 output:

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.如果您将所有 " 替换为 %22 ,您将能够使用此方法传递双引号。

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 ".我已经尝试了所有方法,唯一的方法是在你的 VBS 中指定一些字符串来表示“,并将指定字符串的命令行 arguments 实例替换为”。 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,":!:","""")

Examples I've seen use a backslash before a quote to escape it.我见过的例子在引号前使用反斜杠来转义它。 A common example of this is passing logging options to a setup program (Windows installer package)一个常见的例子是将日志记录选项传递给安装程序(Windows 安装程序包)

Setup.exe /v"/l*v \"c:\My Log Files\test.log\" /qn"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM