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

时间:2015-12-03 16:39:35

标签: java windows batch-file h2

我在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按需要启动。现在我尝试打开W​​indows命令窗口。当我进入同一行并按回车时我得到结果

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文件以及为了能够手动执行它而改变的内容来解释它为什么会起作用吗?我没有看到差异。顺便说一句:当然我首先在命令窗口中浏览C:\Program Files (x86)\H2\bin

1 个答案:

答案 0 :(得分:2)

function isArray(arr) {
  return Object.prototype.toString.call(arr) === '[object Array]';
}

最后的@java -cp "h2-1.3.176.jar;%H2DRIVERS%;%CLASSPATH%" org.h2.tools.Console %* 表示“给这个bat文件的所有参数”。

所以,如果你打电话

%*

然后将调用以下内容

h2.bat param1 param2

但是,在没有bat文件的情况下运行时,字符串@java -cp "h2-1.3.176.jar;%H2DRIVERS%;%CLASSPATH%" org.h2.tools.Console param1 param2 将直接传递给应用程序。 %*不是%*支持的选项之一。