执行.bat文件和手动输入命令的区别

Difference between executing .bat file and entering the command manually

我在 Windows 10(早 7)中使用 H2 数据库已经有一段时间了。在 C:\Program Files (x86)\H2\bin 文件夹中,我有一个 h2.bat,其中第一行是

@java -cp "h2-1.3.176.jar;%H2DRIVERS%;%CLASSPATH%" org.h2.tools.Console %*

当我执行这个文件时,H2 会按需要启动。现在我尝试打开 Windows 命令 window。当我进入同一行并按 return 我得到结果

Starts the H2 Console (web-) server, as well as the TCP and PG server.
Usage: java org.h2.tools.Console <options>
When running without options, -tcp, -web, -browser and -pg are started.
Options are case sensitive. Supported options are:
[-help] or [-?]  Print the list of options
[-url]           Start a browser and connect to this URL
[-driver]        Used together with -url: the driver
[-user]          Used together with -url: the user name
[-password]      Used together with -url: the password
[-web]           Start the web server with the H2 Console
[-tool]          Start the icon or window that allows to start a browser
[-browser]       Start a browser connecting to the web server
[-tcp]           Start the TCP server
[-pg]            Start the PG server
For each Server, additional options are available;
 for details, see the Server tool.
If a service can not be started, the program
 terminates with an exit code of 1.
See also http://h2database.com/javadoc/org/h2/tools/Console.html
Exception in thread "main" org.h2.jdbc.JdbcSQLException: Feature not supported: "%*" [50100-176]
        at org.h2.message.DbException.getJdbcSQLException(DbException.java:344)
        at org.h2.message.DbException.get(DbException.java:178)
        at org.h2.message.DbException.get(DbException.java:154)
        at org.h2.util.Tool.throwUnsupportedOption(Tool.java:69)
        at org.h2.util.Tool.showUsageAndThrowUnsupportedOption(Tool.java:58)
        at org.h2.tools.Console.runTool(Console.java:205)
        at org.h2.tools.Console.main(Console.java:100)

所以你看到我得到了一个 java 异常。你能解释一下为什么它可以通过执行 .bat 文件来工作,以及要更改什么才能手动执行它吗?我看不出有什么区别。顺便说一句:当然,我首先在命令 window.

中浏览到 C:\Program Files (x86)\H2\bin
@java -cp "h2-1.3.176.jar;%H2DRIVERS%;%CLASSPATH%" org.h2.tools.Console %*

最后的%*表示"all the params given to this bat file".

所以如果你打电话给

h2.bat param1 param2

那么下面会被调用

@java -cp "h2-1.3.176.jar;%H2DRIVERS%;%CLASSPATH%" org.h2.tools.Console param1 param2

然而,当 运行 没有 bat 文件时,字符串 %* 会直接传递给应用程序。 %* 不是 org.h2.tools.Console 支持的选项之一。