Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Stack from Powershell, how do I pass test arguments that include a space?

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 ?

like image 383
John Walker Avatar asked May 12 '26 15:05

John Walker


1 Answers

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.

like image 74
mklement0 Avatar answered May 15 '26 06:05

mklement0