DescriptionHi, I'm going mad trying to exectute some shell command ( Is it possible to escape the double quotes?
project:
title: "double quotes"
output-dir: _book
post-render:
- |
pwsh -Command & {
$filename = 'some file with space.pdf'
Copy-Item -Force -Path _book/*pdf -Destination $filename
Start-Process -FilePath 'C:\Program Files\SumatraPDF\SumatraPDF.exe' -ArgumentList `"$filename`"
}
---
title: "double_quotes"
format: pdf
---
## double quotes
the post render does the following, in pwsh
1. set the variable $filename
2. copy the pdf file generated by quarto with $filename
3. open the copied file with SumatraPDF
things falls apart at #3 because the filename has space in it, and `-ArgumentList` will spit a string containing space into a list of arguments. In this case $filename should really be passed enclosed in the double quotes, but the double quotes simply disappears, and I'm not able to escape them so that the string will be formatted correctly |
Replies: 2 comments 1 reply
|
Did you triy your command as a script? Could you try the following code which does not require third party and might help you see what's going on (I don't have a Windows machine or Powershell installed): pwsh -Command & {
$filename = 'some file with space.pdf'
Set-Content -Path file.txt -Value "`"$filename`""
Write-Output "`"$filename`""
} |
|
It doesn't work:
Set-Content:
Line |
3 | Set-Content -Path file.txt -Value `$filename`
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| A positional parameter cannot be found that accepts argument 'Write-Output'.
I think that In the end I decided to rewrite the series of command as pwsh script ( post-render:
- pwsh -Command ./post_render.ps1 'a string with some space.pdf'And it works well enough. |
It doesn't work:
Set-Content -Path file.txt -Value "`"$filename`"will raise an error:Write-Output "`"$filename"`"will print just `$filename" to consoleI think that
`"is converted to a simple'.In the end I decided to rewrite the series of command as pwsh script (
ps1), so that the post_render look like this:And it works well enough.