0

I cannot get the following batch code to work if variable !batDir! contains spaces, e.g. 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.
Shawn
  • 47,241
  • 3
  • 26
  • 60
JPX
  • 167
  • 1
  • 9
  • 1
    Have you tried `'!batDir!ript.ps1'`, i.e. single quotes around the filepath, like with `'!testWithSpaces!'`? – Dávid Laczkó Oct 01 '21 at 08:44
  • Then I got an error `Unexpected token '-filter' in expression or statement.` The variable !test! is -filter. – JPX Oct 01 '21 at 09:04
  • 1
    I think that means that the path has qualified as OK. I would suggest to `echo` the expression first before you pass it to Powershell to debug. – Dávid Laczkó Oct 01 '21 at 09:18
  • `Powershell "'W:\scrips windows\ript.ps1' -filter 'unity*' "` – JPX Oct 01 '21 at 09:35
  • 2
    See [this](https://stackoverflow.com/questions/2035193/how-to-run-a-powershell-script/2035209) to run PS from CMD. – Dávid Laczkó Oct 01 '21 at 09:51

1 Answers1

0

You need to use quotes with &.

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

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

JPX
  • 167
  • 1
  • 9