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

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

问题描述

我试图这样做:

cmd.exe /C "C:\Program Files\Somewhere\SomeProgram.exe" > "C:\temp\Folder Containing Spaces\SomeProgram.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 Files\Somewhere\SomeProgram.exe" > C:\temp\FolderWithNoSpaces\SomeProgram.out

但是,我真的需要第一个工作。 .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,
之后的命令行作为命令行处理,其中以下逻辑是
用于处理引号()字符:

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.


推荐答案

doh。想想我已经回答了我自己的问题。

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天全站免登陆