【问题标题】:How do I run a command with spaces in a github workflow如何在 github 工作流程中运行带有空格的命令
【发布时间】:2021-10-25 16:38:29
【问题描述】:

我需要在 github workflow 中安装 Visual Studio Code 的扩展。我想在工作流中运行这个命令:

run: C:/Program Files/Microsoft VS Code/code.exe --install-extension ms-dynamics-smb.al

但是,github runner 不喜欢这样:

Run C:\Program Files\Microsoft VS Code\code.exe --install-extension ms-dynamics-smb.al
C:\Program: D:\a\_temp\e14dee42-ae33-48ac-ad4e-44f4e4600de5.ps1:2
Line |
   2 |  C:\Program Files\Microsoft VS Code\code.exe --install-extension ms-dy …
     |  ~~~~~~~~~~
     | The term 'C:\Program' is not recognized as a name of a cmdlet, function, script file, or executable
     | program. Check the spelling of the name, or if a path was included, verify that the path is correct
     | and try again.

我尝试了以下变体,但一切都失败了:

run "C:\Program Files\Microsoft VS Code\code.exe --install-extension ms-dynamics-smb.al"
--> Invalid workflow file

run "C:/Program Files/Microsoft VS Code/code.exe --install-extension ms-dynamics-smb.al"
--> The term 'C:/Program' is not recognized as a name of a cmdlet...

run 'C:/Program Files/Microsoft VS Code/code.exe --install-extension ms-dynamics-smb.al'
--> The term 'C:/Program' is not recognized as a name of a cmdlet...

run \"C:/Program Files/Microsoft VS Code/code.exe\" --install-extension ms-dynamics-smb.al
--> The term '\C:/Program Files/Microsoft VS Code/code.exe\' is not recognized...

如何正确处理/转义 github 工作流文件中带有空格的路径?

【问题讨论】:

    标签: windows yaml github-actions


    【解决方案1】:

    怎么样

    run: |
      "C:/Program Files/Microsoft VS Code/code.exe" --install-extension ms-dynamics-smb.al
    

    所以你使用 YAML 块而不是引用单词?

    【讨论】:

    • 谢谢,@AKX,您的解决方案几乎是开箱即用的,我只需要引用包括参数在内的整个命令。
    • 我在这里有点草率。您提出的建议不会引发错误,但由于某种原因该命令未执行。未安装扩展程序。我相应地更新了我的问题。
    • 好吧,如果你回避问题并添加working-directory: "C:/Program Files/Microsoft VS Code/" 并运行code.exe 会怎样?
    • AKXs 解决方案 90% 正确。我必须在命令前添加一个&,并使用稍微不同的路径:& "C:/Program Files/Microsoft VS Code/bin/code.cmd" --install-extension ms-dynamics-smb.al。我尝试将此添加到 AKX 答案,但我的编辑被拒绝。
    猜你喜欢
    • 1970-01-01
    • 2021-12-02
    • 2020-04-02
    • 2020-09-11
    • 2022-01-12
    • 2018-01-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多