在win10中运行,为了在node.js创建解析器,我安装了antlr4工具:
npm install --save-dev antlr4-tool
运行:
c:/prj/parser/node_modules/.bin/antlr4-tool.cmd -o parser grammar/Lang.g4
但收到:
Compiling grammar/Lang.g4...
'which' is not recognized as an internal or external command,
operable program or batch file.
child_process.js:677
throw err;
^
Error: Command failed: which java
'which' is not recognized as an internal or external command,
operable program or batch file.
at checkExecSyncError (child_process.js:637:11)
at Object.execSync (child_process.js:674:13)
at c:prjparsernode_modulesantlr4-tooldistantlr-coreantlr-compiler.js:98:19
at chdir (c:prjparsernode_moduleschdirindex.js:6:13)
at AntlrCompiler.compileJavaScript (c:prjparsernode_modulesantlr4-tooldistantlr-coreantlr-compiler.js:97:9)
at AntlrCompiler.compileTypeScript (c:prjparsernode_modulesantlr4-tooldistantlr-coreantlr-compiler.js:62:38)
at c:prjparsernode_modulesantlr4-tooldistantlr-coreindex.js:40:78
at c:prjparsernode_modulesantlr4-tooldistantlr-coreindex.js:17:23
at arrayEach (c:prjparsernode_moduleslodashlodash.js:516:11)
at Function.forEach (c:prjparsernode_moduleslodashlodash.js:9344:14)
我安装了Java,并且在运行时可以看到它的位置:
where java
,但是由于我在Windows中,我不明白为什么该命令是which
而不是where
...
到达这里的人,这是一个错误,是从Linux和Windows之间的差异(Linux中的which
命令是Windows中的CC_3命令)。
w/a it,仅在您在Windows 中工作时,更改文件:
.../node_modules/antlr4-tool/dist/antlr-core/antlr-compiler.js
,第98行,来自:
child.execSync('which java');
to:
child.execSync('where java');
请参阅https://github.com/mcchatman8009/antlr4-tool/issues/21