我正在尝试这样做:
cmd.exe /C "C:\Program Files\Somewhere\SomeProgram.exe" > "C:\temp\Folder Containing Spaces\SomeProgram.out"
但是,我遇到了与 cmd.exe 工作方式有关的问题。如果您阅读了它的帮助,它会以特殊方式处理 "字符。请参阅问题末尾的帮助。因此,这无法正确执行...我猜 cmd.exe 去掉了一些引号,这使得语句格式错误。
我可以成功地做到这一点:
// quotes not required around folder with no spaces
cmd.exe /C "C:\Program Files\Somewhere\SomeProgram.exe" > C:\temp\FolderWithNoSpaces\SomeProgram.out
但是,我真的需要第一个才能工作。是否存在 cmd.exe 使用的奇怪引用处理?我希望它保留所有引号,但似乎没有让它这样做的选项。
从输出中获取的帮助:cmd/?
如果指定了/C 或/K,则命令行之后的剩余部分 开关作为命令行处理,其中逻辑如下 用于处理引号 (") 字符:
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.
最佳答案
啊。哦。认为我已经回答了我自己的问题。
如果您使用/S,并将整个内容用引号引起来,它只会删除那些外部引号。
cmd.exe /S /C " do what you like here, quotes within the outermost quotes will be preserved "
关于windows - 使用 cmd.exe 时如何处理引号字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/355988/