jbang icon indicating copy to clipboard operation
jbang copied to clipboard

Running Jbang in Powershell needs excessive quoting

Open quintesse opened this issue 3 years ago • 1 comments

We can't run

jbang -c 'println("hey");'

because the quotes around "hey" get stripped out accidentally by the way jbang.ps1 is implemented. To make it work you can escape the quotes like this:

jbang -c 'println(\"hey\");'

But that's undesirable behavior.

The culprit is this line in the startup script: https://github.com/jbangdev/jbang/blob/main/src/main/scripts/jbang.ps1#L157

$output = & "$JAVA_EXEC" $env:JBANG_JAVA_OPTIONS -classpath "$jarPath" dev.jbang.Main @args

The interaction between & and @args is likely the problem.

There is actually a second problem with this line which is that the $env:JBANG_JAVA_OPTIONS is treated as a single parameter which is not what we want, the variable can contain multiple parameters.

quintesse avatar Oct 19 '22 09:10 quintesse

This change fixes the second problem but completely breaks @arg handling:

$output = iex "& '$JAVA_EXEC' $env:JBANG_JAVA_OPTIONS -classpath '$jarPath' dev.jbang.Main @args"

Edit: perhaps this uses more correct quoting for the paths:

$output = iex "& `"$JAVA_EXE`"' $env:JBANG_JAVA_OPTIONS -classpath `"$jarPath`" dev.jbang.Main @args"

quintesse avatar Oct 19 '22 09:10 quintesse