I need to pass the string "fail log" as a tasty pattern argument when running tasty tests out of stack.
This is quite straight forward in bash:
PS C:\Pyrethrum> stack test --fast --ta "-p \"fail log\""
But trying to achieve the same using Powershell is driving me nuts:
PS C:\Pyrethrum> stack test --fast --ta "-p ""fail"" "
works (runs tests) when there is no space
PS C:\Pyrethrum> stack test --fast --ta "-p ""fail log"" "
Error parsing targets: Directory not found: log
PS C:\Pyrethrum> stack test --fast --ta "-p `"fail log`""
tries install a package called log
PS C:\Pyrethrum> stack test --fast --ta "-p \"fail log\""
option --ta: unterminated string: endOfInput
PS C:\Pyrethrum> stack test --fast --ta "-p /fail log/ "
... builds but pattern needs quotes
pyrethrum-0.1.0.0: test (suite: pyrethrum-test, args: -p /fail log/)
option -p: Could not parse pattern
What is the correct command line to get this to run in Powershell ?
Unfortunately, the way PowerShell passes arguments to external programs is broken up to at least PowerShell 7.2.x, and requires you to not just satisfy PowerShell's own syntax requirements with respect to embedded ", but to additionally escape them for the target executable, typically with \:
# `" is needed for PowerShell, \ is needed for stack
stack test --fast --ta "-p \`"fail log\`""
Since your outer "..." string references no PowerShell variables and contains no subexpressions, i.e., since no string interpolation is required, you can use a '...', a literal PowerShell string instead, which simplifies matters a bit:
stack test --fast --ta '-p \"fail log\"'
In short: To pass " characters embedded in an argument to an external program from PowerShell:
\`" inside "..."\" inside '...'See this answer for details, also with respect to a potential future fix and a helper function that hides the bug.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With