将带括号的参数传递给 Windows 批处理文件中包含的 Scala 脚本
我想将一些 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这个 bug 在 scala 2.8.1.final 中不会出现。
我建议改用该版本。
This bug does not occur in scala 2.8.1.final.
I would suggest using that version instead.
我不认为这与 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 :/