【问题标题】:Run PowerShell script with spaces in the file path在文件路径中运行带有空格的 PowerShell 脚本
【发布时间】:2021-11-22 22:19:45
【问题描述】:

如果变量 !batDir! 包含空格,我无法使以下批处理代码工作,例如W:\scripts windows\:

if /I "!i!" GTR "1" (
        Powershell "!batDir!ript.ps1 !test! '!testWithSpaces!' "
        goto :scriptEnd
)

W:\scripts : The term 'W:\scripts' is not recognized as the name of a cmdlet, function, script file, or operable
program.

【问题讨论】:

  • 您是否尝试过'!batDir!ript.ps1',即文件路径周围的单引号,例如'!testWithSpaces!'
  • 然后我得到一个错误Unexpected token '-filter' in expression or statement.变量!test!是-过滤器。
  • 我认为这意味着路径已经合格。我建议先echo 表达式,然后再将其传递给 Powershell 进行调试。
  • Powershell "'W:\scrips windows\ript.ps1' -filter 'unity*' "
  • 请参阅this 从 CMD 运行 PS。

标签: powershell batch-file script


【解决方案1】:

您需要在 & 中使用引号。

Powershell "& '!batDir!ript.ps1' !test! '!testWithSpaces!' "

https://newbedev.com/how-to-run-a-powershell-script-with-white-spaces-in-path-from-command-line

【讨论】:

    猜你喜欢
    • 2018-01-27
    • 2021-08-25
    • 1970-01-01
    • 2015-07-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多