3

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 ?

2

1 Answer 1

6

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:

  • use \`" inside "..."
  • use \" inside '...'

See this answer for details, also with respect to a potential future fix and a helper function that hides the bug.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.