powershellescaping

How can I escape space in PowerShell?


I run this command in PowerShell

Start-Process -FilePath 'C:\Program Files\Typora\Typora.exe' -ArgumentList 'C:\Users\Administrator\Desktop\Hello world.md'

But Typora says

C:\User\Administrator\world.md does not exist

It looks like PowerShell executes

Start-Process -FilePath 'C:\Program Files\Typora\Typora.exe'
     -ArgumentList 'C:\Users\Administrator\Desktop\Hello' 'world.md'

I want to escape the space, but the single-quoted part is not working...

PowerShell version: 5.1.19041.610


Solution

  • PowerShell may not quote strings properly when calling external executables. See

    So to fix this you need to pass the literal " to the exe file by escaping it properly

    Start-Process -FilePath 'C:\Program Files\Typora\Typora.exe' `
        -ArgumentList '"C:\Users\Administrator\Desktop\Hello world.md"'