Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

antlr4-tool fails in Win10 with: Error: Command failed: which java

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

npm install --save-dev antlr4-tool

Ran:

c:/prj/parser/node_modules/.bin/antlr4-tool.cmd -o parser grammar/Lang.g4

But received:

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)

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

where java

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

like image 431
Tar Avatar asked Aug 18 '26 13:08

Tar


1 Answers

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).

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

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

child.execSync('which java');

to:

child.execSync('where java');

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

like image 145
Tar Avatar answered Aug 20 '26 05:08

Tar