使用 cmd.exe 时如何处理引号字符 [英] How do I deal with quote characters when using cmd.exe

查看:41
本文介绍了使用 cmd.exe 时如何处理引号字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试这样做:

cmd.exe /C "C:Program FilesSomewhereSomeProgram.exe" > "C:	empFolder Containing SpacesSomeProgram.out"

但是,我遇到了与 cmd.exe 工作方式有关的问题.如果您阅读它的帮助,它会以特殊方式处理 " 字符.请参阅问题末尾的帮助.因此,这不会正确执行...我猜 cmd.exe 去掉了一些引号,这使得语句格式错误.

However, I have problems which are down to the way cmd.exe works. If you read the help for it, it handles " characters in a special way. See the help at the end of question. So, this doesn't execute correctly... I'm guessing cmd.exe strips some quotes which makes the statement ill-formed.

我可以成功:

// quotes not required around folder with no spaces
cmd.exe /C "C:Program FilesSomewhereSomeProgram.exe" > C:	empFolderWithNoSpacesSomeProgram.out

但是,我真的需要第一个工作.cmd.exe 使用的奇怪的引用处理是否存在?我希望它保留所有引号,但似乎没有办法让它这样做.

But, I really need the first one to work. Is there away around the strange quote processing that cmd.exe uses? I want it to preserve all of the quotes, but there doesn't appear to be an option to make it do that.

从输出中获取的帮助:cmd/?

如果指定了/C 或/K,则后面的命令行的其余部分switch 作为命令行处理,其中的逻辑如下用于处理引号 (") 字符:

If /C or /K is specified, then the remainder of the command line after the switch is processed as a command line, where the following logic is used to process quote (") characters:

1.  If all of the following conditions are met, then quote characters
    on the command line are preserved:

    - no /S switch
    - exactly two quote characters
    - no special characters between the two quote characters,
      where special is one of: &<>()@^|
    - there are one or more whitespace characters between the
      the two quote characters
    - the string between the two quote characters is the name
      of an executable file.

2.  Otherwise, old behavior is to see if the first character is
    a quote character and if so, strip the leading character and
    remove the last quote character on the command line, preserving
    any text after the last quote character.

推荐答案

啊.哦.认为我已经回答了我自己的问题.

Ah. doh. Think I've answered my own question.

如果您使用/S,并将整个内容用引号括起来,它只会删除那些外部引号.

If you use /S, and wrap the whole thing in quotes, it just removes those outer quotes.

cmd.exe /S /C " do what you like here, quotes within the outermost quotes will be preserved "

这篇关于使用 cmd.exe 时如何处理引号字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆