Spaces cause split in path with PowerShell

前端 未结 12 871
广开言路
广开言路 2020-12-02 15:24

I\'m having an issue with powershell when invoking an exe at a path containing spaces.

PS C:\\Windows Services> invoke-expression \"C:\\Windows Services\\My

12条回答
  •  不知归路
    2020-12-02 15:42

    There's a hack I've used since the Invoke-Expression works fine for me.

    You could set the current location to the path with spaces, invoke the expression, get back to your previous location and continue:

    $currLocation = Get-Location
    Set-Location = "C:\Windows Services\"
    Invoke-Expression ".\MyService.exe"
    Set-Location $currLocation
    

    This will only work if the exe doesn't have any spaces in its name.

    Hope this helps

提交回复
热议问题