windows - 使用 cmd.exe 时如何处理引号字符

标签 windows command-line

我正在尝试这样做:

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/

相关文章:

c - 如何在Xcode中编译包含多个文件的C程序

windows - Android Studio - 创建新项目时卡在 "Build Gradle"

windows - Windows 上的 Apache pig 在运行 "hadoop-config.cmd' 时给出 "pig -x local"is not recognized as an internal or external command”错误

command-line - Anaconda Prompt 命令行命令

ubuntu - 使用 imagemagick 从命令行添加可见的登录 pdf

windows - 如何在Powershell中从 `clip`输入的末尾修剪换行符?

windows - Powershell脚本无法读取AD电话号码

c# - 将 Windows 窗体对象添加到列表框

windows - ASM x64 中 40h REX 操作码的用途是什么?

batch-file - 批处理文件按日期提供文件计数