简体   繁体   English

如何将包含双引号的字符串作为参数传递到BAT文件

[英]How to pass a string containing double quotes to a BAT file as an argument

My C# program needs to pass a string to a BAT file as the argument of the BAT file. 我的C#程序需要将字符串作为BAT文件的参数传递给BAT文件。 This string may contain arbitrary characters such as double quotes, space and etc. I tried to escape all the characters by prefixing it by ^ but it does not work for the double quotes. 该字符串可以包含任意字符,例如双引号,空格等。我试图通过用^前缀将所有字符转义,但不适用于双引号。 I tried to escape the double quote by prefixing it with “\\” but it adds a “\\” to the argument when it is passed to the BAT file. 我试图通过在其前面加上“ \\”来对双引号进行转义,但是在将其传递到BAT文件时,会在参数中添加一个“ \\”。 For example: if mystring is “hello “there” &test”, the argument becomes “Hello \\”there\\” &test”. 例如:如果mystring是“ hello“ there”&test”,则参数变为“ Hello \\” there \\”&test”。 How can I pass the string “hello “there” &test” as the argument? 如何传递字符串“ hello” there”和“ test”作为参数? Can anyone help please? 有人可以帮忙吗?

尝试这个

@"hello ""there"" &test"

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

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