【问题标题】:for /f run powershell escape charactersfor /f 运行 powershell 转义字符
【发布时间】:2013-05-17 12:12:30
【问题描述】:

当我在 cmd 提示符下运行以下命令时,它工作正常

pushd "C:\Converter"
for /f "delims=" %g in ('dir "C:\Toconvert" /b /s /ad') do (powershell .\BatchConvert.ps1 "%g" 10)
popd

成功执行命令。 这是输出:

C:\Converter>(powershell .\BatchConvert.ps1 "C:\Toconvert\Prego!PDF" 10 )

当我尝试在 .bat 文件中运行相同的命令时,它失败了。使用 cmd 行运行 bat 文件,我发现它正在生成:

C:\Converter>for /f "delims=" \Toconvert" /b /s /ad') do (powershell .\BatchConvert.ps1 "g" 10)

为什么它在括号前去掉 "%g in ('dir "C:" 以及为什么它在 do 命令中去掉 %?如何转义字符以使其作为 .bat 工作?

【问题讨论】:

  • % 在批处理文件中使用时必须加倍为%%
  • 完美!我一直在用头撞桌子,试图用谷歌搜索问题是什么。谢谢!

标签: automation cmd


【解决方案1】:

在批处理文件中使用时,% 必须加倍为 %% – dbenham 2013 年 5 月 17 日 12:39

【讨论】:

    猜你喜欢
    • 2020-02-28
    • 2021-07-13
    • 1970-01-01
    • 2021-12-16
    • 1970-01-01
    • 2015-10-26
    • 2021-06-20
    • 2010-10-07
    • 1970-01-01
    相关资源
    最近更新 更多