antlr4-tool 在 Win10 中失败:错误:命令失败:which java [英] antlr4-tool fails in Win10 with: Error: Command failed: which java

查看:49
本文介绍了antlr4-tool 在 Win10 中失败:错误:命令失败:which java的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Win10下运行,为了尝试在Node.JS中创建解析器,我安装了ANTLR4工具:

Running in Win10, in an attempt to create a parser in Node.JS, I installed ANTLR4 tool:

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:\prj\parser\node_modules\antlr4-tool\dist\antlr-core\antlr-compiler.js:98:19
    at chdir (c:\prj\parser\node_modules\chdir\index.js:6:13)
    at AntlrCompiler.compileJavaScript (c:\prj\parser\node_modules\antlr4-tool\dist\antlr-core\antlr-compiler.js:97:9)
    at AntlrCompiler.compileTypeScript (c:\prj\parser\node_modules\antlr4-tool\dist\antlr-core\antlr-compiler.js:62:38)
    at c:\prj\parser\node_modules\antlr4-tool\dist\antlr-core\index.js:40:78
    at c:\prj\parser\node_modules\antlr4-tool\dist\antlr-core\index.js:17:23
    at arrayEach (c:\prj\parser\node_modules\lodash\lodash.js:516:11)
    at Function.forEach (c:\prj\parser\node_modules\lodash\lodash.js:9344:14)

我安装了 Java,运行时可以看到它的位置:

I have Java install, and I can see its location when running:

where java

但由于我在 Windows 中,我不明白为什么命令是 which 而不是 where...

But since I'm in Windows, I don't understand why the command is which and not where...

推荐答案

对于任何人来说,这是一个错误,显然源于 Linux 和 Windows 之间的差异(Linux 中的 which 命令是 where 在 Windows 中).

To whomever gets here, it's a bug, apprently stemming from the difference between Linux and Windows (which command in Linux is where in Windows).

要避免它,仅当您在 Windows 中工作时,请更改文件:

To W/A it, only if you work in Windows, change the file:

.../node_modules/antlr4-tool/dist/antlr-core/antlr-compiler.js,第 98 行,来自:

.../node_modules/antlr4-tool/dist/antlr-core/antlr-compiler.js, line #98, from:

child.execSync('which java');

到:

child.execSync('where java');

参见 https://github.com/mcchatman8009/antlr4-tool/issues/21

这篇关于antlr4-tool 在 Win10 中失败:错误:命令失败:which java的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆