You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Azure Pipeline CmdLine@2任务中传递含空格的路径

问题

我尝试使用Azure Pipelines的CmdLine@2任务通过命令行脚本运行Inno安装程序,任务配置如下:

- task: CmdLine@2
  displayName: 'Running Inno Installer for GSB'
  inputs:
    script: 'C:/Program Files (x86)/Inno Setup 6/Compil32.exe /cc $(gsbInstallerFile)'

但由于Inno编译器的路径包含空格,导致任务执行失败。

注:Inno安装程序确实存在于该路径下,且变量$(gsbInstallerFile)不含空格,其解析结果为:

C:\agent\_work\4\s/Main/Application/GSB/Installer/GSB.Installer.iss

我尝试了以下几种写法,但均未成功:

script: '\"C:/Program Files (x86)/Inno Setup 6/Compil32.exe /cc $(gsbInstallerFile)\"'
script: "C:/Program Files (x86)/Inno Setup 6/Compil32.exe /cc $(gsbInstallerFile)"
script: "\"C:/Program Files (x86)/Inno Setup 6/Compil32.exe /cc $(gsbInstallerFile)\""
script: '"C:/Program Files (x86)/Inno Setup 6/Compil32.exe" /cc $(gsbInstallerFile)'

得到的典型错误信息如下:

'\"C:/Program Files (x86)/Inno Setup 6/Compil32.exe /cc C:\agent\_work\4\s/Main/Application/GSB/Installer/GSB.Installer.iss\"' is not recognized as an internal or external command

请问如何正确处理含空格的路径,使该任务能够正常执行?

解决方法

正确的写法是单独给包含空格的可执行文件路径加双引号,同时用单引号包裹整个script内容,避免YAML转义问题:

- task: CmdLine@2
  displayName: 'Running Inno Installer for GSB'
  inputs:
    script: '"C:/Program Files (x86)/Inno Setup 6/Compil32.exe" /cc $(gsbInstallerFile)'

核心说明

  • Windows命令行规则:仅需给含空格的可执行文件路径加双引号,无需包裹整个命令;
  • YAML语法规则:用单引号包裹script内容时,内部的双引号不需要额外转义,Azure Pipelines会直接将正确的命令传递给cmd.exe执行。

也可以改用Windows原生反斜杠路径写法,效果完全一致:

script: '"C:\Program Files (x86)\Inno Setup 6\Compil32.exe" /cc $(gsbInstallerFile)'

内容的提问来源于stack exchange,提问作者Joe

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.12 04:02:35