在Windows批处理文件斯卡拉脚本 [英] Scala scripts in Windows batch files
问题描述
在Scala编程,它提供了有关如何运行批处理文件斯卡拉脚本(的链接)。
In Programming in Scala, it gives a description on how to run Scala scripts from batch files (link).
对于Windows
::#!
@echo off
call scala %0 %*
goto :eof
::!#
我有谷歌搜索问题 ::#!
。这是什么意思?我知道:
表示注释和Unix的#!
是要用于外壳一个方向,但什么是不是正是这里?和 ::#!
?
I'm having a problem googling ::#!
. What does this mean? I know ::
denotes a comment and in Unix #!
is a direction to the shell to be used, but what is it exactly here? And the ::!#
?
这到底是什么%0%*
的意思,而且是有必要的前preSS是这样吗?
What exactly does %0 %*
mean, and is it necessary to express it like this?
是否有可能从同一个批处理文件运行多个脚本?
Is it possible to run multiple scripts from the same batch file?
推荐答案
这是一个噱头,但它的作品。它打算复制的Unix shell的调用特定命令来处理一个shell文件的能力。所以,这里的解释是:
This is a gimmick, but it works. It intends to replicate Unix shell's ability to invoke a particular command to process a shell file. So, here's the explanation:
::#!
与启动:
是Windows Shell中的意见,所以这只是一个评论。行
Lines starting with ::
are comments in Windows shell, so this is just a comment.
@echo off
不显示从这里开始执行的行。在 @
开头确保这条线本身将不会被显示。
Don't show lines executed from here on. The @
at the beginning ensure this line itself won't be shown.
call scala %0 %*
执行权转交给斯卡拉
脚本。在%0
表示这个文件本身的名称(以便斯卡拉可以找到它),而%*
是参数在执行过程中被通过了。
Transfer execution to the scala
script. The %0
means the name of this file itself (so that scala can find it), and %*
are the parameters that were passed in its execution.
举例来说,说这些线在一个名为 count.bat
,并通过键入调用它数1 2 3
。在这种情况下,该行会执行阶数1 2 3
- 在这种情况下,你会得到一个错误。你必须通过键入调用它 count.bat
。
For example, say these lines are in a file called count.bat
, and you invoked it by typing count 1 2 3
. In this case, that line will execute scala count 1 2 3
-- in which case you'll get an error. You must invoke it by typing count.bat
.
goto :eof
完成执行脚本。
::!#
另一个注释行。
所以,这里的诀窍...斯卡拉,调用一次,会发现作为第一个参数传递的文件,检查第一行是 ::#!
,不顾一切到行 ::#!
如果是这样,然后执行该文件的其余部分(在行::#!
)作为Scala的脚本。
So, here's the trick... Scala, once invoked, will find the file passed as the first argument, check if the first line is ::#!
, ignore everything up to the line ::!#
if so, and then execute the rest of the file (the lines after ::!#
) as a Scala script.
在换句话说,它不是Windows的外壳,是聪明的,它的斯卡拉。 : - )
In other words, it is not the Windows shell that is smart, it's Scala. :-)
这篇关于在Windows批处理文件斯卡拉脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!