ことの起こり
ant の exec タスクを使っていたところ、 notepad は起動できるけど groovyConsole は起動できないという現象が発生。
色々ためしていたら、 groovyConsole を groovyConsole.bat にしたら起動できた。
原因
調べてたら、 Ant のマニュアル にそれっぽい記述を見つける。
The task delegates to Runtime.exec which in turn apparently calls ::CreateProcess. It is the latter Win32 function that defines the exact semantics of the call. In particular, if you do not put a file extension on the executable, only ".EXE" files are looked for, not ".COM", ".CMD" or other file types listed in the environment variable PATHEXT.
exec タスクは Runtime.exec() を使っているが、それは最終的に CreateProcess という Windows の関数を使用している。
この CreateProcess は、拡張子を省略した場合 PATHEXT で指定している他の拡張子を全て無視して、 .EXE のファイルしか解決してくれないらしい。
このため、 Runtime.exec() メソッドを使った場合、たとえパスを通していても .bat などの非 exe ファイルはファイル名だけで起動することができない。
今回遭遇したケースでは、 notepad は notepad.exe だからファイル名だけで起動できたが、 groovyConsole は groovyConsole.bat しかなかったのでファイル名だけでは起動できなかった。
Gradle の Exec も同じ
Gralde の Exec も同じ現象が発生する。