将带括号的参数传递给 Windows 批处理文件中包含的 Scala 脚本

发布于 2024-10-08 09:00:29 字数 865 浏览 0 评论 0原文

我想将一些 Scala 脚本放入批处理文件中。如果你只是打印参数,规范的方式将是这样的:(

::#!
@echo off
scala %0 %*
goto :eof
::!#
args foreach println

这实际上调用另一个批处理脚本,Scala 的 bin 目录中的 scala.bat)。如果我尝试向其传递包含括号的参数,Windows 命令行解释器会抱怨语法错误:

printargs.bat "foo(bar)baz"

奇怪的是,如果我创建一个仅包含 args foreach println< 的 scala 文件 printargs.scala /code>,这可以正常工作:

scala printargs.scala "foo(bar)baz"

所以我认为这不是 scala.bat 中的错误。但我能做什么呢?

更新:实际错误发生在 scala.bat 中的以下行:

set _ARGS=%*

带有错误消息

baz was unexpected at this time

如果我更改 scala.bat 它不使用局部变量而是使用 % * 直接运行,就可以正常运行。所以我提交了一份错误报告。在错误修复之前,问题仍然是是否有解决此问题的方法。

I'd like to put some Scala scripts into a batch file. If you just print the arguments, the canonical way would be like this:

::#!
@echo off
scala %0 %*
goto :eof
::!#
args foreach println

(This actually calls another batch script, scala.bat from the bin-directory of Scala). If I try to pass an argument containing parentheses to it, the windows command line interpreter complains with a syntax error:

printargs.bat "foo(bar)baz"

Strangely, if I create a scala file printargs.scala containing just args foreach println, this works correctly:

scala printargs.scala "foo(bar)baz"

So I assume this is not a bug in scala.bat. But what can I do?

Update: the actual error occurs in the following line in scala.bat:

set _ARGS=%*

with the error message

baz was unexpected at this time

If I change scala.bat that it does not use a local variable but use %* directly, it works correctly. So I filed a bug-report. The question remains if there is a workaround for this problem until the bug is fixed.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

棒棒糖 2024-10-15 09:00:29

这个 bug 在 scala 2.8.1.final 中不会出现。
我建议改用该版本。

This bug does not occur in scala 2.8.1.final.
I would suggest using that version instead.

吝吻 2024-10-15 09:00:29

我不认为这与 Scala 有任何关系。我目前在将包含括号的参数传递到 grails 命令时遇到同样的问题。显然这是 Windows shell 的问题,已尝试转义字符“(”,但这不起作用:/

I don't think this has anything to do with Scala.. I'm currently having the same problem with passing an argument which contains parentheses into a grails command. Apparently this is a problem with the windows shell, have tried escaping the characters "(" but that does not work :/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文